Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

alias emacs='/Applications/'
alias octave='/Applications/'
alias wine='/Applications/'
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
up vote 5 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/ /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

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/ "$@"; }
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

Simple solution is to add the following command in .bash_profile:

alias rstudio='open -a /Applications/ "$@"'

This will allow the program RStudio to open any existing .R file passed to the command

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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