Input and output redirection in the Bourne shell
There are redirection options that can be used in commands.
In general, most commands do not know whether their input or output is associated with the keyboard, the display screen, or a file. Thus, a command can be used conveniently either at the keyboard or in a pipeline.
The following redirection options can appear anywhere in a simple command. They can also precede or follow a command, but are not passed to the command.
Item | Description |
---|---|
<File | Uses the specified file as standard input. |
>File | Uses the specified file as standard output. Creates the file if it does not exist; otherwise, truncates it to zero length. |
> >File | Uses the specified file as standard output. Creates the file if it does not exist; otherwise, adds the output to the end of the file. |
<<[-]eofstr | Reads as standard input all lines from the eofstr variable
up to a line containing only eofstr or up to an end-of-file
character. If any character in the eofstr variable is quoted,
the shell does not expand or interpret any characters in the input lines.
Otherwise, it performs variable and command substitution and ignores a quoted
newline character (\ newline). Use a backslash (\ )
to quote characters within the eofstr variable or within
the input lines. If you add a hyphen (-)
to the |
<&Digit | Associates standard input with the file descriptor specified by the Digit variable. |
>&Digit | Associates standard output with the file descriptor specified by the Digit variable. |
<&- | Closes standard input. |
>&- | Closes standard output. |
Note: The restricted shell does not allow output redirection.
For more information about redirection, see Input and output redirection.