Eshell is both a command shell and an Emacs Lisp REPL. As a result, you can invoke commands in two different ways: in command form or in Lisp form.
You can use the semicolon (;
) to separate multiple command
invocations on a single line, executing each in turn. You can also
separate commands with &&
or ||
. When using &&
,
Eshell will execute the second command only if the first succeeds
(i.e. has an exit status of 0); with ||
, Eshell will execute
the second command only if the first fails.
A command invocation followed by an ampersand (&
) will be run
in the background. Eshell has no job control, so you can not suspend
or background the current process, or bring a background process into
the foreground. That said, background processes invoked from Eshell
can be controlled the same way as any other background process in
Emacs.
Command form looks much the same as in other shells. A command consists of arguments separated by spaces; the first argument is the command to run, with any subsequent arguments being passed to that command.
~ $ echo hello hello
The command can be either an Elisp function or an external command. Eshell looks for the command in the following order:
If you would prefer to use ordinary Lisp functions over external
programs, set the option eshell-prefer-lisp-functions
to
t
. This will swap the lookup order of the last two items. You
can also force Eshell to look for a command as an external program by
prefixing its name with *, like *command
(see Built-in commands).
You can also group command forms together into a subcommand with curly
braces ({}
). This lets you use the output of a subcommand as
an argument to another command, or within control flow statements
(see Control Flow).
~ $ echo {echo hello; echo there} hellothere
Lisp form looks like ordinary Emacs Lisp code, because that’s what it is. As a result, you can use any syntax normally available to an Emacs Lisp program (see The Emacs Lisp Reference Manual).
~ $ (format "hello, %s" user-login-name) hello, user
In addition, you can combine command forms and Lisp forms together into single statements, letting you use whatever form is the most convenient for expressing your intentions.
~ $ ls *.patch > (format-time-string "%F.log")
This command writes a list of all files matching the glob pattern
*.patch
(see Globbing) to a file named
current-date.log
(see Redirection).