Redirection in Eshell is similar to that of other command shells. You
can use the output redirection operators >
and >>
, but
there is not yet any support for input redirection. In the cases
below, fd specifies the file descriptor to redirect; if not
specified, file descriptor 1 (standard output) will be used by
default.
> dest
fd> dest
Redirect output to dest, overwriting its contents with the new output.
>> dest
fd>> dest
Redirect output to dest, appending it to the existing contents of dest.
>>> dest
fd>>> dest
Redirect output to dest, inserting it at the current mark if
dest is a buffer, at the beginning of the file if dest is
a file, or otherwise behaving the same as >>
.
&> dest
>& dest
Redirect both standard output and standard error to dest, overwriting its contents with the new output.
&>> dest
>>& dest
Redirect both standard output and standard error to dest, appending it to the existing contents of dest.
&>>> dest
>>>& dest
Redirect both standard output and standard error to dest,
inserting it like with >>> dest
.
>&other-fd
fd>&other-fd
Duplicate the file descriptor other-fd to fd (or 1 if unspecified). The order in which this is used is significant, so
command > file 2>&1
redirects both standard output and standard error to file, whereas
command 2>&1 > file
only redirects standard output to file (and sends standard error to the display via standard output’s original handle).
Eshell supports redirecting output to several different types of targets:
Virtual targets are mapping of device names to functions. Eshell comes with four virtual devices:
Does nothing with the output passed to it.
Writes the text passed to it to the display.
Adds the text passed to it to the kill ring.
Adds the text passed to it to the clipboard.
You can, of course, define your own virtual targets. They are defined
by adding a list of the form ‘("/dev/name" function
mode)’ to eshell-virtual-targets
. The first element is
the device name; function may be either a lambda or a function
name. If mode is nil
, then the function is the output
function; if it is non-nil
, then the function is passed the
redirection mode as a symbol–overwrite
for >
,
append
for >>
, or insert
for >>>
–and the
function is expected to return the output function.
The output function is called once on each line of output until
nil
is passed, indicating end of output.