egor7
egor7

Reputation: 4941

Execution environment of the script (eshell vs bash)

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

Upvotes: 3

Views: 407

Answers (3)

egor7
egor7

Reputation: 4941

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

Upvotes: 0

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

Upvotes: 5

phils
phils

Reputation: 73246

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?

Upvotes: 1

Related Questions