3

How to determine inside a script - whether it has been executed from a eshell or from a normal shell (bash, etc.)?

egor7
  • 4,678
  • 7
  • 31
  • 55
  • It might be worth logging a bug report for this (`M-x report-emacs-bug`), as it seems entirely reasonable that `eshell` should add similar environment variables to those available with the other Emacs shell options. – phils Mar 26 '12 at 00:47

3 Answers3

5

Eshell doesn't set any particular environment variable. You can check $TERM: it's set to dumb under Eshell.

A more precise check would look at the parent process of the script

if [ -t 1 ] && [ "$TERM" = "dumb" ] && [ "$(ps -o comm= -p $PPID)" = "emacs" ]; then
  echo "This looks a lot like eshell"
fi
Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
1

I initially marked this as a duplicate of How do I tell a shell that it is running from within Emacs?, but I think the answer there is flawed or outdated, as although it explicitly mentions eshell, it only seems to apply to shell and term and ansi-term. eshell must be the only kind of shell you can run in Emacs that doesn't set an obvious environment variable?

Community
  • 1
  • 1
phils
  • 71,335
  • 11
  • 153
  • 198
  • Correct - the answer for those question is not suitable here: `echo $EMACS` in both cases gives nothing for eshell whithin emacs and for bash, etc. So please unmark this question as 'duplicate'. – egor7 Mar 25 '12 at 11:14
  • The vote can't be removed, but as it requires several votes to close a question as a duplicate, there's really nothing to worry about. – phils Mar 25 '12 at 12:20
0

Simply add (setenv "EMACS" "t") to ~/.emacs. So the behavior would be the same in all emacs shells.

egor7
  • 4,678
  • 7
  • 31
  • 55
  • 1
    Of course if the intention is to write a portable script which happens to behave nicely for anyone running it under eshell, this won't help. – phils Mar 28 '12 at 11:17