Before a command is executed, its input and output may be redirected using a special notation interpreted by the shell. Redirection allows commands' file handles to be duplicated, opened, closed, made to refer to different files, and can change the files the command reads from and writes to. Redirection may also be used to modify file handles in the current shell execution environment. The following redirection operators may precede or appear anywhere within a simple command or may follow a command. Redirections are processed in the order they appear, from left to right.
Each redirection that may be preceded by a file descriptor number may instead be preceded by a word of the form{varname}
. In this case, for each redirection operator except >&-
and <&-
, the shell will allocate a file descriptor greater than or equal to 10 and assign it to {varname}
. If >&-
or<&-
is preceded by {varname}
, the value of {varname}
defines the file descriptor to close.