bash alias disappears when opening new terminal

Viewed 4411

im setting up a new alias by typing this command:

vi ~/.bashrc 

and then placing my alias:

alias school='ssh -Y username@linux.student.cs.uwaterloo.ca'

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?

1 Answers

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.

Related