I'm curious, why does adding an entry to .bashrc cause a link to be overwritten? For example, on a testing machine, I installed Java with apt-get install openjdk-7-jre and then played round with .bashrc by adding alias java="echo Java!". When I ran java from bash, I found that it echoed Java! instead of running java, located at /usr/bin/java. I have also found that this happens with ps, sh and screen. So why is this happening?

  • 2
    This is exactly what alias is supposed to do - replace the alias with the specified command when typed in the bash prompt. – baochan Aug 4 '15 at 18:56

Because that is how Bash works. It's in the manual - Aliases have a higher priority when trying to match input up with a command.

The common use of aliases is to override commands; for example:

alias java="\java -Xmx=1G"

The above alias raises the default maximum amount of memory available to a java process from 256MiB to 1GiB. The only way for this to have any useful effect, however, is if when I type java, it runs the alias and not the command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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