Take the tour ×

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?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

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.

share|improve this answer
Is that how homebrew/apt-get does it? where are these links? echo $PATH gives: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/texbin:/usr/X11/b‌​in What would be a good place for these links? –  Hans-Peter E. Kristiansen Feb 5 '12 at 21:34
@Hans-PeterE.Kristiansen Homebrew/apt-get install to these directories, usually /usr/bin or /usr/local/bin. Homebrew creates /usr/local/bin and adds it to the PATH, so you can run the programs without typing their full name. With Homebrew, there's some additional link creation going on as well, so in that regard it's similar. I'd place the links in /usr/bin (as shown in the example) or /usr/local/bin, since you already have it. It's possible you need to prefix the ln command with sudo to be able to write to these directories. –  Daniel Beck Feb 5 '12 at 21:38
@Hans-PeterE.Kristiansen You won't see Homebrew installed programs in /Applications. They are stored in subdirectories of /usr/local. Run /usr/local/bin to see the links created for them. –  Daniel Beck Feb 5 '12 at 21:46
add comment

That is the right way to do it, just for a different value of "it" to what you want to achieve. (alias is just for interactive use, pretty much.)

The way to open an app bundle on the Mac is to use open -a ${appname}, so you could / should replace your emacs alias with alias emacs='open -a aquamacs', and your inkscape with open -a wine '/Users/hpek/.wine/...'.

The way that you have a directly executable emacs binary, though, is to have something named literally that on your $PATH. I tend toward tiny scripts:

exec /usr/bin/open -a octave "$@"

That opens the application the "mac" way, passes all the command line arguments through it, and is executable from anything including other processes.

If you only care about the shell, though, shell functions are more "normal" than aliases, in that they can be triggered in more circumstances in bash:

function octave() { /Applications/Octave.app/.../bin/octave "$@"; }
function octave() { open -a octave "$@"; }
share|improve this answer
The first open command should be open -a Aquamacs. Chances are the open -a octave "$@" examples are missing --args. –  Daniel Beck Feb 5 '12 at 21:40
What does "$@" mean, and where do I read about it? –  Hans-Peter E. Kristiansen Feb 5 '12 at 22:03
@Hans-PeterE.Kristiansen "$@" is all arguments to the function or script in order, individually quoted. See man bash in the section Special Parameters. –  Daniel Beck Feb 5 '12 at 22:21
add comment

Your Answer


