4

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?

codeforester
  • 28,846
  • 11
  • 78
  • 104
SqR_08
  • 51
  • 4
  • 1
    What's the exact error message you get? – melpomene Nov 12 '18 at 22:25
  • 1
    so `.bashrc` is not sourced when you login. Search for `.bash_bashrc` or `.bash_profile` or `.profile` etc. – KamilCuk Nov 12 '18 at 22:41
  • See [lhunath](https://stackoverflow.com/users/58803/lhunath)'s very useful answer to understand how these things work: [About .bash_profile, .bashrc, and where should alias be written in?](https://stackoverflow.com/a/903213/6862601). – codeforester Nov 12 '18 at 23:50

1 Answers1

4

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.

Amit Bhardwaj
  • 313
  • 1
  • 8