How to determine inside a script - whether it has been executed from a eshell or from a normal shell (bash, etc.)?
Asked
Active
Viewed 373 times
3 Answers
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?
-
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
-
1Of 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