In Emacs I can run a shell using following commands -
M-x term
M-x shell
M-x eshell
What is the difference between these three?
In Emacs I can run a shell using following commands -
M-x term
M-x shell
M-x eshell
What is the difference between these three?
shell
is the oldest of these 3 choices. It uses Emacs's comint-mode
to run a subshell (e.g. bash
). In this mode, you're using Emacs to edit a command line. The subprocess doesn't see any input until you press Enter. Emacs is acting like a dumb terminal. It does support color codes, but not things like moving the cursor around, so you can't run curses-based applications.
term
is a terminal emulator written in Emacs Lisp. In this mode, the keys you press are sent directly to the subprocess; you're using whatever line editing capabilities the shell presents, not Emacs's. It also allows you to run programs that use advanced terminal capabilities like cursor movement (e.g. you could run nano
or less
inside Emacs).
eshell
is a shell implemented directly in Emacs Lisp. You're not running bash
or any other shell as a subprocess. As a result, the syntax is not quite the same as bash
or sh
. It allows things like redirecting the output of a process directly to an Emacs buffer (try echo hello >#<buffer results>
).
According to Xahlee page:
shell
is the standard emacs interface to Operating System's command line interface.
term
(ansi-term is pretty much same to term today. They were different packages, but now both defined in term.el) is a terminal emulator. It behaves like a dedicated terminal app, such as {xterm, gnome-terminal, puTTY}. It is compatible to more shell apps than emacs shell interface, but standard emacs keys such as moving cursor don't work here (because it is emulating a terminal.)
eshell
is a shell written entirely in emacs lisp. Note: it is not a bash emulator. Eshell is a shell by itself, but similar to bash or other shells.
Which should you use?
It depends on your preference.
shell
is good for general use of classic/standard unix shell commands, such as {grep, du, ls, sort, cat, head, tail, uname, …}.
term & ansi-term
are good if you want to run stuff like ssh, or other command line interactive interface (such as {python, ruby, lisp} shell), or text based GUI app such as {vim, synaptic, …}.
eshell
is good especially on Microsoft Windows where bash is not installed, or, if you are a emacs lisp programer, because eshell has direct access to emacs lisp.
eshell
will have them too if you have those programs installed.
– Bart Louwers
Jan 08 '17 at 23:27
which grep
in eshll says "eshell/grep is a "compiled Lisp function in `em-unix.el', of cause the grep in your system can be executed in eshell, like I said eshell is very useful in MS which a lot small tools like grep are not installed.
– CodyChan
Jan 09 '17 at 05:40
eshell
can not distinguish between stdout and stderr. If you redirect ineshell
, you always redirect both. – ceving Feb 21 '22 at 09:46