4

im setting up a new alias by typing this command:

vi ~/.bashrc 

and then placing my alias:

alias school='ssh -Y [email protected]' 

followed by exiting the file using: wq

however when i close my terminal and open my terminal, i get a "command can't be found." error message.

if i type source ~/.bash_aliases, it will work, the alias will work, but when i open a new terminal it won't.

is my .bashrc supposed to be empty when i vi into it?

3
  • 1
    What's the exact error message you get? Commented Nov 12, 2018 at 22:25
  • 1
    so .bashrc is not sourced when you login. Search for .bash_bashrc or .bash_profile or .profile etc. Commented Nov 12, 2018 at 22:41
  • See lhunath's very useful answer to understand how these things work: About .bash_profile, .bashrc, and where should alias be written in?. Commented Nov 12, 2018 at 23:50

1 Answer 1

6

The reason your alias is getting lost is because you dont have your bashrc sourced in a new terminal.

Same will happen even if you create a new alias file and source it in bashrc because its scope gets limited to the terminal you are editing in.

What you can do is logout once and then log in back so that bashrc entries gets updated for your user account or you can source in each terminal by typing

source ~/.bashrc 

By adding the same entry to '''.profile''' you are making sure the alias is set on each system boot.

So its better to set the alias in .bashrc rather than .profile

Another major point to nite here is to make sure you dont delete anything in bashrc since that will do catastrophic changes to you session.

Sign up to request clarification or add additional context in comments.

3 Comments

is there a way to make my alias permanent instead of doing "source ~/.bashrc" every time?
As i commented in my answer you do a logout/login session and that should work for you.
This is the only thing worked after setting alias in ~/.bash_profile, before that every time I was needed to source the bash_profile when I opened a new terminal on macOS Catalina and BTY the solution is permanent.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.