Bash – the correct way to alias applications in OS X through bash

aliasbashbashrc

In my ~/.bashrc, I have several aliases like:

alias emacs='/Applications/Aquamacs.app/Contents/MacOS/Aquamacs'
alias octave='/Applications/Octave.app/Contents/Resources/bin/octave'
alias wine='/Applications/Wine.app/Contents/Resources/bin/wine'
alias simion='wine "/Users/hpek/.wine/drive_c/Program Files/SIMION 8.0/simion.exe"'
alias inkscape='wine "/Users/hpek/.wine/drive_c/Program Files/Inkscape/inkscape.exe"'

I do not think that this is the right way to do it. The aliases does not work from within bash scripts, and when installing something through brew or apt-get, it does not create an alias like this.

What is the correct way to do this?

Best Answer

Aliases don't work in shell script by design. Otherwise e.g. alias rm='rm -i' will break most shell scripts.

To enable them anyway, set the expand_aliases shell option.


You can create softlinks for these executables in a directory on your $PATH:

ln -s /Applications/Aquamacs.app/Contents/MacOS/Aquamacs /usr/bin/aquamacs

Then just type the new command name, e.g. aquamacs, to run them.

This will allow use of these commands independent of your shell.


Note that for regular OS X applications, a non-blocking way to open them is open -a ProgramName, e.g. open -a Aquamacs. It uses Launch Services' program database (the one e.g. providing the selection of programs for opening a certain file with a non-default editor) and knows where the applications are installed.