Up
Next
Previous
Input/output
The standard input and standard output of a command may be redirected with the
following syntax:
-
< name
-
Open file name (which is first variable, command and filename
expanded) as the standard input.
-
<< word
-
Read the shell input up to a line which is identical to word. word
is not subjected to variable, filename or command substitution, and each input
line is compared to word before any substitutions are done on this input
line. Unless a quoting `\', `"', `' or ``' appears in word variable and
command substitution is performed on the intervening lines, allowing `\' to
quote `$', `\' and ``'. Commands which are substituted have all blanks, tabs,
and newlines preserved, except for the final newline which is dropped. The
resultant text is placed in an anonymous temporary file which is given to the
command as standard input.
> name
>! name
>& name
-
>&! name
-
The file name is used as standard output. If the file does not exist
then it is created; if the file exists, its is truncated, its previous contents
being lost.
>> name
>>& name
>>! name
-
>>&! name
-
Like `>', but appends output to the end of name.
If the shell variable noclobber is set, then it is an error for
the file not to exist, unless one of the `!' forms is given.
A command receives the environment in which the shell was invoked as modified
by the input-output parameters and the presence of the command in a pipeline.
Thus, unlike some previous shells, commands run from a file of shell commands
have no access to the text of the commands by default; rather they receive the
original standard input of the shell. The `<<' mechanism should be used to
present inline data. This permits shell command scripts to function as
components of pipelines and allows the shell to block read its input. Note
that the default standard input for a command run detached is not
the empty file /dev/null, but the original standard input of the shell.
If this is a terminal and if the process attempts to read from the terminal,
then the process will block and the user will be notified (see Jobs).
Diagnostic output may be directed through a pipe with the standard output.
Simply use the form `|&' rather than just `|'.
The shell cannot presently redirect diagnostic output without also redirecting
standard output, but `(command > output-file) >& error-file'
is often an acceptable workaround. Either output-file or
error-file may be `/dev/tty' to send output to the terminal.
Up
Next
Previous