2

[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!

  • 5
    Please specify how you are creating alias in question ? – g_p Oct 1 '14 at 19:06
  • 1
    It is also usually suggest that you rather create the aliases in the ~/.bash_aliases file (create it if it does not exist) just to keep things tidy. – chesedo Oct 2 '14 at 16:46
  • 2
    Good idea - but you should suggest to source ~/.bash_aliases in ~/.bashrc. The file is not part of the standard bash startup files. – Volker Siegel Oct 2 '14 at 16:59
  • @VolkerSiegel At least on recent versions of Ubuntu, the default .bashrc does check for .bash_aliases and sources it if it exists. – Eliah Kagan Oct 9 '14 at 16:21
3

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

1

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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.