Previous: , Up: Entry Points [Contents][Index]


2.3 Scripts

Like other shells, you can create Eshell scripts. An Eshell script is simply a file containing a sequence of commands that will be executed as though you entered them one at a time in an interactive Eshell session. You can invoke these scripts from within Eshell with source, which will run the script in a subshell. If you wish to run a script in your current Eshell environment, use the . command instead.

Like with aliases (see Aliases), Eshell scripts can accept any number of arguments. Within the script, you can refer to these with the special variables 0ドル, 1ドル, …, 9ドル, and $*.

You can also invoke Eshell scripts from outside of Eshell:

Command: eshell-execute-file file &optional args output-target error-target

Execute the Eshell commands contained in file, passing an optional list of args to the script. If output-target is t (interactively, with the prefix argument), write the command output to the current buffer. If nil, don’t write the output anywhere. For any other value, output to the corresponding Eshell target (see Redirection).

error-target is similar to output-target, except that it controls where to write standard error, and a nil value means to write standard error to the same place as standard output. (To suppress standard error, you can write to the Eshell virtual target /dev/null\.)

Function: eshell-batch-file

You can use this function in the interpreter directive of an Eshell script file to make the script executable from outside of Emacs:

#!/usr/bin/env -S emacs --batch -f eshell-batch-file

As with other ways of invoking Eshell scripts, you can pass extra arguments to the script on the command line.


Previous: One-Off Commands, Up: Entry Points [Contents][Index]

AltStyle によって変換されたページ (->オリジナル) /