1

I'm trying to create a permanent alias. I've created one long ago, but I don't remember if I did anything differently than what I'm doing now. Be as it may, it isn't working!

I start by opening the terminal and type

nano ~/.bashrc

Then I scroll to the end (just in case, I don't know) and type

alias pd="pwd"

(this is not the alias I'm actually creating).

When I close and save the bashrc file I type pd and the command isn't recognized. Plus, when I type the alias command to see my aliases, the pd doesn't show!

However, If I type bash (I'm using the fish shell) the terminal goes back to normal (sorry for my high-tech lingo) and the aliases are created and I can use them!

Is there anything I'm doing wrong?

Thanks!

8
  • I see you’ve found a way to sort it. However, I suspect your original method (in the question) will work - but only if you tell the shell to re-read your .bashrc file: once you’ve saved your edited file, type . .bashrc (note the leading . followed by space) - and it should work. Alternatively close and reopen the terminal.
    – Will
    Commented Nov 17, 2022 at 11:50
  • @Will I didn't type that, but I closed and reopened the terminal. I even restarted the computer xD Thanks anyway! Commented Nov 17, 2022 at 12:07
  • Might be interesting to see if forcing a .bashrc read as above would work - create a temporary alias in .bashrc and try forcing the read then see if it works - just for interest / next time you need to do this. I don’t use fish so may not be good advice I gave!
    – Will
    Commented Nov 17, 2022 at 12:11
  • @Will I wrote it as you said (just typed . .bashrc on the terminal) and got back this: .bashrc (line 6): 'case' builtin not inside of switch block case $- in ^ from sourcing file .bashrc .: Error while reading file “.bashrc” I don't know what this means. Commented Nov 17, 2022 at 12:16
  • Fish and bash are both shells, they are the same kind of thing, but they are not the same shell. .bashrc is the configuration file for the bash shell, anything you do there won't affect the fish shell. If you want to do things to fish, you need to modify its configuration file, not bash's! This is why nothing works for you until you run bash: running bash starts a new bash shell, and since you have modified bash's configuration file, the changes will take effect now that you run bash.
    – terdon
    Commented Nov 17, 2022 at 13:38

1 Answer 1

1

Basically, in the fish shell, you type

alias pd="pwd"

which creates a temporary alias. To turn it into a permanent one you do

funcsave pd

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .