aboutsummaryrefslogtreecommitdiffstats
path: root/doc/misc
diff options
context:
space:
mode:
authorJim Porter2023-01-15 18:35:31 -0800
committerJim Porter2023-01-17 13:58:36 -0800
commitc4f0b6ccea128d52a7b4a9ddc1e81dcf13bb25ea (patch)
tree3ad6fa8f0194a558eb6016a216906b0752d2f275 /doc/misc
parentdbac923b9df97706d3944c21edfc9117b408d80c (diff)
downloademacs-c4f0b6ccea128d52a7b4a9ddc1e81dcf13bb25ea.tar.gz
emacs-c4f0b6ccea128d52a7b4a9ddc1e81dcf13bb25ea.zip
Add more detail about how to invoke Eshell commands
* doc/misc/eshell.texi (Variables): Move footnote explaining "REPL" from here... (Top): ... to its first use here. (Commands): Move explanation about kernel functions to here. (Invocation): Describe command form and Lisp form. Fix documentation about priority of commands in command form. (Arguments): Add a cross reference to the Invocation node.
Diffstat (limited to 'doc/misc')
-rw-r--r--doc/misc/eshell.texi136
1 files changed, 100 insertions, 36 deletions
diff --git a/doc/misc/eshell.texi b/doc/misc/eshell.texi
index 4ad1c3f74f6..1789cded9d3 100644
--- a/doc/misc/eshell.texi
+++ b/doc/misc/eshell.texi
@@ -64,10 +64,11 @@ modify this GNU manual.''
64 64
65Eshell is a shell-like command interpreter implemented in Emacs Lisp. 65Eshell is a shell-like command interpreter implemented in Emacs Lisp.
66It invokes no external processes except for those requested by the 66It invokes no external processes except for those requested by the
67user. It is intended to be an alternative to the IELM (@pxref{Lisp Interaction, Emacs Lisp Interaction, , emacs, The Emacs Editor}) 67user. It is intended to be an alternative to the IELM (@pxref{Lisp
68REPL for Emacs @emph{and} with an interface similar to command shells 68Interaction, Emacs Lisp Interaction, , emacs, The Emacs Editor})
69such as @command{bash}, @command{zsh}, @command{rc}, or 69REPL@footnote{Short for ``Read-Eval-Print Loop''.} for Emacs
70@command{4dos}. 70@emph{and} with an interface similar to command shells such as
71@command{bash}, @command{zsh}, @command{rc}, or @command{4dos}.
71@c This manual is updated to release 2.4 of Eshell. 72@c This manual is updated to release 2.4 of Eshell.
72 73
73@insertcopying 74@insertcopying
@@ -193,6 +194,13 @@ In a command shell, everything is done by invoking commands. This
193chapter covers command invocations in Eshell, including the command 194chapter covers command invocations in Eshell, including the command
194history and invoking commands in a script file. 195history and invoking commands in a script file.
195 196
197Unlike regular system shells, Eshell never invokes kernel functions
198directly, such as @code{exec(3)}. Instead, it uses the Lisp functions
199available in the Emacs Lisp library. It does this by transforming the
200input line into a callable Lisp form.@footnote{To see the Lisp form
201that will be invoked, type this as the Eshell prompt:
202@kbd{eshell-parse-command 'echo hello'}}
203
196@menu 204@menu
197* Invocation:: 205* Invocation::
198* Arguments:: 206* Arguments::
@@ -207,23 +215,16 @@ history and invoking commands in a script file.
207 215
208@node Invocation 216@node Invocation
209@section Invocation 217@section Invocation
210Unlike regular system shells, Eshell never invokes kernel functions 218Eshell is both a command shell and an Emacs Lisp @acronym{REPL}. As a
211directly, such as @code{exec(3)}. Instead, it uses the Lisp functions 219result, you can invoke commands in two different ways: in @dfn{command
212available in the Emacs Lisp library. It does this by transforming the 220form} or in @dfn{lisp form}.
213input line into a callable Lisp form.@footnote{To see the Lisp form that will be invoked, type: @samp{eshell-parse-command "echo hello"}}
214 221
215The command can be either an Elisp function or an external command. 222You can use the semicolon (@code{;}) to separate multiple command
216Eshell looks first for an alias (@pxref{Aliases}) with the same name as the 223invocations on a single line, executing each in turn. You can also
217command, then a built-in (@pxref{Built-ins}) or a function with the 224separate commands with @code{&&} or @code{||}. When using @code{&&},
218same name; if there is no match, it then tries to execute it as an 225Eshell will execute the second command only if the first succeeds
219external command. 226(i.e.@: has an exit status of 0); with @code{||}, Eshell will execute
220 227the second command only if the first fails.
221The semicolon (@code{;}) can be used to separate multiple command
222invocations on a single line. You can also separate commands with
223@code{&&} or @code{||}. When using @code{&&}, Eshell will execute the
224second command only if the first succeeds (i.e.@: has an exit
225status of 0); with @code{||}, Eshell will execute the second command
226only if the first fails.
227 228
228A command invocation followed by an ampersand (@code{&}) will be run 229A command invocation followed by an ampersand (@code{&}) will be run
229in the background. Eshell has no job control, so you can not suspend 230in the background. Eshell has no job control, so you can not suspend
@@ -232,12 +233,80 @@ the foreground. That said, background processes invoked from Eshell
232can be controlled the same way as any other background process in 233can be controlled the same way as any other background process in
233Emacs. 234Emacs.
234 235
236@subsection Command form
237Command form looks much the same as in other shells. A command
238consists of arguments separated by spaces; the first argument is the
239command to run, with any subsequent arguments being passed to that
240command.
241
242@example
243~ $ echo hello
244hello
245@end example
246
247@cindex order of looking for commands
248@cindex command lookup order
249The command can be either an Elisp function or an external command.
250Eshell looks for the command in the following order:
251
252@enumerate
253@item
254As a command alias (@pxref{Aliases})
255
256@item
257As a built-in command (@pxref{Built-ins})
258
259@item
260As an external program
261
262@item
263As an ordinary Lisp function
264@end enumerate
265
266@vindex eshell-prefer-lisp-functions
267If you would prefer to use ordinary Lisp functions over external
268programs, set the option @code{eshell-prefer-lisp-functions} to
269@code{t}. This will swap the lookup order of the last two items.
270
271You can also group command forms together into a subcommand with curly
272braces (@code{@{@}}). This lets you use the output of a subcommand as
273an argument to another command, or within control flow statements
274(@pxref{Control Flow}).
275
276@example
277~ $ echo @{echo hello; echo there@}
278hellothere
279@end example
280
281@subsection Lisp form
282Lisp form looks like ordinary Emacs Lisp code, because that's what it
283is. As a result, you can use any syntax normally available to an
284Emacs Lisp program (@pxref{Top, , , elisp, The Emacs Lisp Reference
285Manual}).
286
287@example
288~ $ (format "hello, %s" user-login-name)
289hello, user
290@end example
291
292In addition, you can @emph{combine} command forms and Lisp forms
293together into single statements, letting you use whatever form is the
294most convenient for expressing your intentions.
295
296@example
297~ $ ls *.patch > (format-time-string "%F.log")
298@end example
299
300This command writes a list of all files matching the glob pattern
301@code{*.patch} (@pxref{Globbing}) to a file named
302@code{@var{current-date}.log} (@pxref{Redirection}).
303
235@node Arguments 304@node Arguments
236@section Arguments 305@section Arguments
237Ordinarily, command arguments are parsed by Eshell as either strings 306Ordinarily, Eshell parses arguments in command form as either strings
238or numbers, depending on what the parser thinks they look like. To 307or numbers, depending on what the parser thinks they look like. To
239specify an argument of some other data type, you can use an 308specify an argument of some other data type, you can use a Lisp form
240@ref{Dollars Expansion, Elisp expression}: 309(@pxref{Invocation}):
241 310
242@example 311@example
243~ $ echo (list 1 2 3) 312~ $ echo (list 1 2 3)
@@ -354,10 +423,6 @@ eshell/sudo is a compiled Lisp function in `em-tramp.el'.
354sudo is an alias, defined as "*sudo $*" 423sudo is an alias, defined as "*sudo $*"
355@end example 424@end example
356 425
357@vindex eshell-prefer-lisp-functions
358If you would prefer to use the built-in commands instead of the external
359commands, set @code{eshell-prefer-lisp-functions} to @code{t}.
360
361Some of the built-in commands have different behavior from their 426Some of the built-in commands have different behavior from their
362external counterparts, and some have no external counterpart. Most of 427external counterparts, and some have no external counterpart. Most of
363these will print a usage message when given the @code{--help} option. 428these will print a usage message when given the @code{--help} option.
@@ -923,15 +988,14 @@ For example, you could handle a subset of the options for the
923@node Variables 988@node Variables
924@section Variables 989@section Variables
925@vindex eshell-prefer-lisp-variables 990@vindex eshell-prefer-lisp-variables
926Since Eshell is a combination of an Emacs @acronym{REPL}@footnote{ 991Since Eshell is a combination of an Emacs @acronym{REPL} and a command
927Short for ``Read-Eval-Print Loop''. 992shell, it can refer to variables from two different sources: ordinary
928} and a command shell, it can refer to variables from two different 993Emacs Lisp variables, as well as environment variables. By default,
929sources: ordinary Emacs Lisp variables, as well as environment 994when using a variable in Eshell, it will first look in the list of
930variables. By default, when using a variable in Eshell, it will first 995built-in variables, then in the list of environment variables, and
931look in the list of built-in variables, then in the list of 996finally in the list of Lisp variables. If you would prefer to use
932environment variables, and finally in the list of Lisp variables. If 997Lisp variables over environment variables, you can set
933you would prefer to use Lisp variables over environment variables, you 998@code{eshell-prefer-lisp-variables} to @code{t}.
934can set @code{eshell-prefer-lisp-variables} to @code{t}.
935 999
936You can set variables in a few different ways. To set a Lisp 1000You can set variables in a few different ways. To set a Lisp
937variable, you can use the command @samp{setq @var{name} @var{value}}, 1001variable, you can use the command @samp{setq @var{name} @var{value}},