I noticed that terminal-based emacs and GUI emacs seems to work differently in terms of shell environment, even if they are started in the same terminal session.

For example, I'm working with roslisp right now, in which I start emacs, and load my package with a command which includes calling a shell command rospack that search for my package.

If I'm doing it from a GUI emacs started from a properly configured shell session(that is, I could use rospack to find my package from the shell session), the command called inside emacs wouldn't be able to find my package. If I call rospack find my_package in eshell, the same output is produced; however if I call it in term, it could find my package sucessfully

If I'm doing it from a terminal-based emacs started in the very same shell session, the command called inside emacs would be able to find my package.

However, as tested, all environment variables should be inherited in both. If I export NEW_ENV=foo in the shell session just before starting both, getenv would be able to find NEW_ENV with value foo.

due to this behaviour, I now work primarily with a terminal-based emacs server and emacsclient -c for GUI.

The only literature I find relevent as of now is this blog from XahLee, which does not say anything on this behaviour. I wonder if there's anything different in how GUI emacs and terminal-based emacs interact with shell that accounts for this behaviour?

  • Perhaps this is not an Emacs feature/bug. In a graphical interface, applications inherit environment variables in a different way than you might think.
    – shynur
    Commented Jul 29, 2023 at 15:48
  • Which operating system are you using?
    – Trevoke
    Commented Jul 29, 2023 at 15:57
  • Just to really confirm: When you say "If I'm doing it from a GUI emacs started from a properly configured shell session" you definitely mean that you're starting your GUI Emacs by executing the command emacs in that shell, yes? You're not running it using a desktop icon or anything like that? And you're not running emacsclient and connecting to a server that wasn't started from your shell? (Or inadvertently using an alias which does something like that?) A GUI emacs and a terminal emacs -nw started from the same shell should inherit the same environment.
    – phils
    Commented Jul 29, 2023 at 15:58
  • Before you start the emacs gui, run type emacs in your shell. This will tell you if it is an alias, function, script or the emacs program itself.
    – db48x
    Commented Jul 30, 2023 at 1:01
  • 1
    @phils yes, I did emacs in the shell session, Ctrl-c in the same session to shut down, then emacs -nw in the very same session.
    – Herman He
    Commented Aug 5, 2023 at 13:12


Your Answer

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

Browse other questions tagged or ask your own question.