0

I recently started coding in C (college class) and use Emacs as my primary text editor. In my class, we use the terminal to create new files and open existing ones, and I decided I wanted to be able to do the same thing on my MacBook. After I downloaded Emacs, I noticed that it would only open files, new and existing, inside my terminal and not in a separate window. I decided then to open up my .zshrc file and add the following line:

alias emacs='$(/Applications/Emacs.app/Contents/MacOS/Emacs "$@")'

I was hoping this line would allow me to open any file, new or existing, in a separate Emacs window rather than inside the terminal. However, after adding that line to my .zshrc file, every time I type in my terminal "emacs [existing file name].c &", the terminal will say "command not found: [existing file name].c" and an entirely new Emacs file with the name of the already existing file will be created and open.

I've made sure I'm in the correct directory, but I'm quite new to all this so I'm not sure what could be wrong. Any help is appreciated! Thank you!

1 Answer 1

1

Your alias is wrong; remove the $(…) around the invocation of Emacs. $(…) is called a “command substitution”; it runs whatever is inside the parens and captures anything it prints, then inserts what was printed where the substitution was. In your case, you are running Emacs when you are defining the alias, and then the alias is defined to be whatever Emacs happened to print, which is almost always nothing. So the alias gets defined to be the empty string, as if you had run alias emacs="". So when you later run emacs foo.c, the alias is substituted and the whole command line becomes just foo.c. And of course that gives you an error because foo.c isn’t an executable.

1
  • 1
    Thanks so much for the help + explanation! Apr 20, 2023 at 0:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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