Problem in creating alias, get strange messages

[Reviewers: note that the question was completely rewritten after the close votes.]

I recently found how I can define aliases for bash in the ~/.bashrc.

But since I tried that, I see the followig messages eveery time I open a terminal.

I added some bash aliases to my I was trying to create shortcuts using alias but I unsuccessful and somehow managed to get the message below every time I open up a new terminal.

bash: alias: UIC: not found
bash: alias: =: not found
bash: alias: sudo openvpn --config ~/vpn/UIC-alopez78.ovpn: not found
bash: alias: mat: not found
bash: alias: =: not found
bash: alias: cd /home/alexisblopez/MATLAB/R2014a/bin/: not found
bash: alias: lab: not found
bash: alias: =: not found
bash: alias: ./matlab: not found
~$ 

Its's confusing; it does not say error, but because my aliases do not work,
I think I did something wrong with them - I don't know what!


Probably you defined these alias in .bashrc file:

alias UIC = 'sudo openvpn --config ~/vpn/UIC-alopez78.ovpn'
alias mat = 'cd /home/alexisblopez/MATLAB/R2014a/bin/'
alias lab = './matlab'

You should edit .bashrc and remove space before and after =:

alias UIC='sudo openvpn --config ~/vpn/UIC-alopez78.ovpn'
alias mat='cd /home/alexisblopez/MATLAB/R2014a/bin/'
alias lab='./matlab'

save your changes and run source .bashrc


The error messages look interesting.
The lines

bash: alias: =: not found

that is: bash gives us the message that it's builtin command, alias, gave it the message "not found" for something named "=".

Now, alias is involved, and there is a = in a place where it is mistaken for a command. For the = to be treated as a command, it must be a single word, with spaces.

And looking at the syntax of the command alias (see help alias below), that's wrong: The = must be used without spaces around,, like this:

alias foo='bar baz'

So, the idea is that there are alias definitions that have extra space around =, which separates the one command line argument of alias into three arguments.

Let's make an experiment: Can we replicate your error message like this?

$ alias mat = 'foo bar'
bash: alias: mat: not found
bash: alias: =: not found
bash: alias: foo bar: not found

Yes!

The alias builtin command tries to show the definitions of the three aliases mat, =, and foo bar, as requested, and complains not to find them.


Solution: read help alias, find the alias definitions, and remove the space around the =.


$ help alias
alias: alias [-p] [name[=value] ... ]
    Define or display aliases.

    Without arguments, `alias' prints the list of aliases in the reusable
    form `alias NAME=VALUE' on standard output.

    Otherwise, an alias is defined for each NAME whose VALUE is given.
    A trailing space in VALUE causes the next word to be checked for
    alias substitution when the alias is expanded.

    Options:
      -p        Print all defined aliases in a reusable format

    Exit Status:
    alias returns true unless a NAME is supplied for which no alias has been
    defined.