14

I'm trying to set my $EDITOR variable to be emacs with no window, so the command to call it would be emacs -nw. However if I set it like this:

export EDITOR="/Applications/Emacs.app/Contents/MacOS/Emacs -nw"

I get the following error

zsh: no such file or directory: /Applications/Emacs.app/Contents/MacOS/Emacs -n

1
  • Have you checked if the programs take environment variables of configuration files to set such switches?
    – vonbrand
    Jan 23, 2013 at 18:59

2 Answers 2

11

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 $@.

8

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .