It is possible to run a shell from within Emacs; there are a few
different ways to do so. The easiest way is to type M-x shell
. This
creates a a buffer called *shell* with a shell
prompt. Shell commands you type are sent to a system shell and the
output displayed in the shell buffer. One thing you'll notice in shell
mode is that the arrow keys move you around the buffer - they don't
access command history as they do in most shells. To access command
history, use M-p
and M-n
for previous and next, respectively.
One of the drawbacks of shell-mode is that it is not suitable for
full-screen applications (like less, lynx, mutt or pine), to run these
inside of Emacs, you need to use a terminal mode. Type M-x ansi-term
,
and specify which shell you would like to run (your default will be
the shell you are using, e.g. /usr/pkg/bin/bash
).
On platforms without an underlying shell (e.g., Windows), Emacs has a
terminal emulator written entirely in Emacs Lisp. To enter it, type
M-x eshell
. While not suitable for full-screen applications, it does
emulate a limited subset of shell features rather nicely. In this
shell mode, the arrow keys work as you would expect, and most shell
builtins and shell aliases work as well. Some external commands such
as grep work, although input/output redirection is not yet
implemented.
Here are the commands we discussed above:
M-x shell | Shell mode, use M-p and M-n for command history |
M-x eshell | Emacs Lisp shell emulator, use arrow keys for command history |
M-x ansi-term | Full terminal emulator, suitable for full-screen applications. |