Unix environment variables with arguments

I believe this doesn't work because the shell would try to open a binary with the space included in the file name, so Emacs -nw, and not open Emacs and then pass -nw as the options.

How about making $EDITOR a small (executable) script, e.g. in ~/bin/EDITOR?

#!/bin/sh
/Applications/Emacs.app/Contents/MacOS/Emacs -nw -- "$@"

Then, simply add to your shell's configuration:

export EDITOR=~/bin/EDITOR

Now, EDITOR will call the script with the appropriate arguments, expanded in $@.


As explained here: zsh: Command not found (for $EDITOR) , zsh treats the expanded variable as a single word (that has space characters in it).

Possible solutions are:

  • run in bash which expands the spaces properly

  • Use the '=' modifier on parameter expansion: see Expansion in the zsh documentation and look for '${=spec}'

  • use eval when calling $EDITOR as in:

    eval $EDITOR file