sh(1) sh(1)
sh, rsh, ksh, rksh - a standard/restricted command and programming
language
sh [ -abCefhikmnprstuvx ] [ -o option ] ... [ -c string ] [ arg ... ]
/usr/lib/rsh [ -abCefhikmnprstuvx ] [ -o option ] ... [ -c string ]
[ arg ... ]
Note: As of IRIX 6.4, sh is the Korn shell rather than the Bourne shell.
See bsh(1) for the Bourne Shell description. See the COMPATIBILITY
ISSUES section below for more detail.
sh is a command and programming language that executes commands read from
a terminal or a file. /usr/lib/rsh is a restricted version of the
standard command interpreter sh; it is used to set up login names and
execution environments whose capabilities are more controlled than those
of the standard shell. See Invocation below for the meaning of arguments
to the shell.
Definitions [Toc] [Back]
A metacharacter is one of the following characters:
; & ( ) | < > newline space tab
A blank is a tab or a space. An identifier is a sequence of letters,
digits, or underscores starting with a letter or underscore. Identifiers
are used as names for functions and variables. A word is a sequence of
characters separated by one or more non-quoted metacharacters.
A command is a sequence of characters in the syntax of the shell
language. The shell reads each command and carries out the desired
action either directly or by invoking separate utilities. A special
command is a command that is carried out by the shell without creating a
separate process. Except for documented side effects, most special
commands can be implemented as separate utilities.
Commands [Toc] [Back]
A simple-command is a sequence of blank separated words which may be
preceded by a variable assignment list (see Environment below). The
first word specifies the name of the command to be executed. Except as
specified below, the remaining words are passed as arguments to the
invoked command. The command name is passed as argument 0 [see exec(2)].
The value of a simple-command is its exit status if it terminates
normally, or (octal) 200+status if it terminates abnormally [see
signal(2) for a list of status values].
A pipeline is a sequence of one or more commands separated by |. The
standard output of each command but the last is connected by a pipe(2) to
the standard input of the next command. Each command is run as a
Page 1
sh(1) sh(1)
separate process; the shell waits for the last command to terminate. The
exit status of a pipeline is the exit status of the last command.
A list is a sequence of one or more pipelines separated by ;, &, &&, or
||, and optionally terminated by ;, &, or |&. Of these five symbols, ;,
&, and |& have equal precedence, which is lower than that of && and ||.
The symbols && and || also have equal precedence. A semicolon (;) causes
sequential execution of the preceding pipeline; an ampersand (&) causes
asynchronous execution of the preceding pipeline (that is, the shell does
not wait for that pipeline to finish). The symbol |& causes asynchronous
execution of the preceding command or pipeline with a two-way pipe
established to the parent shell. The standard input and output of the
spawned command can be written to and read from by the parent shell using
the -p option of the special commands read and print described later.
The symbol && (||) causes the list following it to be executed only if
the preceding pipeline returns a zero (nonzero) value. An arbitrary
number of newlines may appear in a list, instead of a semicolon, to
delimit a command.
A command is either a simple-command or one of the following. Unless
otherwise stated, the value returned by a command is that of the last
simple-command executed in the command.
for identifier [ in word ... ] ; do list <b>; done
Each time a for command is executed, identifier is set to the next
word taken from the in word list. If in word ... is omitted, the
for command executes the do list once for each positional parameter
that is set (see Parameter Substitution below). Execution ends when
there are no more words in the list.
select identifier [ in word ... ] ; do list <b>; done
A select command prints on standard error (file descriptor 2), the
set of words, each preceded by a number. If in word ... is
omitted, the positional parameters are used instead (see Parameter
Substitution below). The PS3 prompt is printed and a line is read
from the standard input. If this line consists of the number of one
of the listed words, the value of the parameter identifier is set to
the word corresponding to this number. If this line is empty the
selection list is printed again. Otherwise the value of the
parameter identifier is set to null. The contents of the line read
from standard input is saved in the variable REPLY. The list is
executed for each selection until a break or end-of-file is
encountered.
case word <b>in [ [(]pattern [ | pattern ] ... ) list ;; ] ... esac
A case command executes the list associated with the first pattern
that matches word. The form of the patterns is the same as that
used for file-name generation (see Filename Generation below).
if list <b>; then list [ elif list <b>; then list ] ... [ ; else list ] ; fi
The list following if is executed and, if it returns a zero exit
status, the list following the first then is executed. Otherwise,
Page 2
sh(1) sh(1)
the list following elif is executed and, if its value is zero, the
list following the next then is executed. Failing that, the else
list is executed. If no else list or then list is executed, the if
command returns a zero exit status.
while list ; do list <b>; done
until list ; do list <b>; done
A while command repeatedly executes the while list and, if the exit
status of the last command in the list is zero, executes the do
list; otherwise the loop terminates. If no commands in the do list
are executed, the while command returns a zero exit status; until
may be used in place of while to negate the loop termination test.
(list<b>)
Execute list in a separate environment. Note, that if two adjacent
open parentheses are needed for nesting, a space must be inserted to
avoid arithmetic evaluation as described below.
{ list<b>;}
list is simply executed. The { must be followed by a space. Note
that unlike the metacharacters ( and ), { and } are reserved words
and must be typed at the beginning of a line or after a ; in order
to be recognized.
[[expression<b>]]
Evaluates expression and returns a zero exit status when expression
is true. See Conditional Expressions below, for a description of
expression.
function identifier <b>{ list<b>;}
identifier () { list<b>;}
Define a function which is referenced by identifier. The body of
the function is the list of commands between { and } (see Functions
below). The { must be followed by a space.
time pipeline
The pipeline is executed and the elapsed time as well as the user
and system time are printed on standard error. Note that the
reported times reflect the elapsed time for both the parent and the
child processes in order to give a more accurate view of the total
time the pipeline took to execute.
The following reserved words are only recognized as the first word of a
command and when not quoted:
if then else elif fi case esac for while until do done { }
function select time [[ ]]
Comments [Toc] [Back]
A word beginning with # causes that word and all the following characters
up to a newline to be ignored.
Page 3
sh(1) sh(1)
Aliasing [Toc] [Back]
The first word of each command is replaced by the text of an alias if an
alias for this word has been defined. An alias name consists of any
number of characters excluding meta-characters, quoting characters, file
expansion characters, parameter and command substitution characters and
=. The replacement string can contain any valid shell script including
the metacharacters listed above. The first word of each command in the
replaced text, other than any that are in the process of being replaced,
is tested for aliases. If the last character of the alias value is a
blank the word following the alias is also checked for alias
substitution. Aliases can be used to redefine special builtin commands
but cannot be used to redefine the reserved words listed above. Aliases
can be created, listed, and exported with the alias command and can be
removed with the unalias command. Exported aliases remain in effect for
scripts invoked by name, but must be reinitialized for separate
invocations of the shell (see Invocation below).
Aliasing is performed when scripts are read, not while they are executed.
Therefore, for an alias to take effect the alias definition command has
to be executed before the command which references the alias is read.
Aliases are frequently used as a short hand for full pathnames. An
option to the aliasing facility allows the value of the alias to be
automatically set to the full pathname of the corresponding command.
These aliases are called tracked aliases. The value of a tracked alias
is defined the first time the corresponding command is looked up and
becomes undefined each time the PATH variable is reset. These aliases
remain tracked so that the next subsequent reference redefines the value.
Several tracked aliases are compiled into the shell. The -h option of
the set command makes each referenced command name into a tracked alias.
The following exported aliases are compiled into the shell but can be
unset or redefined:
autoload='typeset -fu'
false='let 0'
functions='typeset -f'
hash='alias -t'
history='fc -l'
integer='typeset -i'
nohup='nohup '
r='fc -e -'
true=':'
type='whence -v'
Tilde Substitution [Toc] [Back]
After alias substitution is performed, each word is checked to see if it
begins with an unquoted ~. If it does, the word up to a / is checked to
see if it matches a user name in the /etc/passwd file. If a match is
found, the ~ and the matched login name is replaced by the login
directory of the matched user. This is called a tilde substitution. If
Page 4
sh(1) sh(1)
no match is found, the original text is left unchanged. A ~ by itself,
or in front of a /, is replaced by $HOME. A ~ followed by a + or - is
replaced by $PWD and $OLDPWD respectively.
In addition, tilde substitution is attempted when the value of a variable
assignment begins with a ~.
Command Substitution [Toc] [Back]
The standard output from a command enclosed in parentheses preceded by a
dollar sign ( $() ) or a pair of grave accents (``) may be used as part
or all of a word; trailing newlines are removed. In the second (archaic)
form, the string between the quotes is processed for special quoting
characters before the command is executed (see Quoting below). The
command substitution $(cat file) can be replaced by the equivalent but
faster $(<file). Command substitution of most special commands that do
not perform input/output redirection are carried out without creating a
separate process.
An arithmetic expression enclosed in double parentheses and preceded by a
dollar sign [$(())] is replaced by the value of the arithmetic expression
within the double parentheses.
Parameter Substitution [Toc] [Back]
A parameter is an identifier, one or more digits, or any of the
characters *, @, #, ?, -, $, and !. A variable (a parameter denoted by
an identifier) has a value and zero or more attributes. Variables can be
assigned values and attributes by using the typeset special command. The
attributes supported by the shell are described later with the typeset
special command. Exported parameters pass values and attributes to the
environment.
The shell supports a one-dimensional array facility. An element of an
array variable is referenced by a subscript. A subscript is denoted by a
[, followed by an arithmetic expression (see Arithmetic Evaluation below)
followed by a ]. To assign values to an array, use
set -A name value <b>...
The value of all subscripts must be in the range of 0 through 1023.
Arrays need not be declared. Any reference to a variable with a valid
subscript is legal and an array is created if necessary. Referencing an
array without a subscript is equivalent to referencing the element zero.
The value of a variable may also be assigned by writing:
name<b>=value [ name<b>=value ] ...
If the integer attribute, -i, is set for name the value is subject to
arithmetic evaluation as described below.
Page 5
sh(1) sh(1)
Positional parameters, parameters denoted by a number, may be assigned
values with the set special command. Parameter $0 is set from argument
zero when the shell is invoked.
The character $ is used to introduce substitutable parameters.
${parameter<b>}
The shell reads all the characters from ${ to the matching } as part
of the same word even if it contains braces or metacharacters. The
value, if any, of the parameter is substituted. The braces are
required when parameter is followed by a letter, digit, or
underscore that is not to be interpreted as part of its name or when
a variable is subscripted. If parameter is one or more digits it is
a positional parameter. A positional parameter of more than one
digit must be enclosed in braces. If parameter is * or @, all the
positional parameters, starting with $1, are substituted (separated
by a field separator character). If an array identifier with
subscript * or @ is used, the value for each of the elements is
substituted (separated by a field separator character).
${#parameter<b>}
If parameter is * or @, the number of positional parameters is
substituted. Otherwise, the length of the value of the parameter is
substituted.
${#identifier<b>[*]}
The number of elements in the array identifier is substituted.
${parameter<b>:-word<b>}
If parameter is set and is non-null, substitute its value; otherwise
substitute word.
${parameter<b>:=word<b>}
If parameter is not set or is null, set it to word; the value of the
parameter is substituted. Positional parameters may not be assigned
to in this way.
${parameter<b>:?word<b>}
If parameter is set and is non-null, substitute its value;
otherwise, print word and exit from the shell. If word is omitted,
a standard message is printed.
${parameter<b>:+word<b>}
If parameter is set and is non-null, substitute word; otherwise
substitute nothing.
${parameter<b>#pattern<b>}
${parameter<b>##pattern<b>}
If the shell pattern matches the beginning of the value of
parameter, the value of this substitution is the value of the
parameter with the matched portion deleted; otherwise the value of
this parameter is substituted. In the first form the smallest
Page 6
sh(1) sh(1)
matching pattern is deleted and in the second form the largest
matching pattern is deleted.
${parameter<b>%pattern<b>}
${parameter<b>%%pattern<b>}
If the shell pattern matches the end of the value of parameter, the
value of this substitution is the value of the parameter with the
matched part deleted; otherwise substitute the value of parameter.
In the first form the smallest matching pattern is deleted and in
the second form the largest matching pattern is deleted.
In the above, word is not evaluated unless it is to be used as the
substituted string, so that, in the following example, pwd is executed
only if d is not set or is null:
echo ${d:-$(pwd)}
If the colon (:) is omitted from the above expressions, the shell only
checks whether parameter is set or not.
The following parameters are automatically set by the shell:
# The number of positional parameters in decimal.
- Flags supplied to the shell on invocation or by the set command.
? The decimal value returned by the last executed command.
$ The process number of this shell.
_ Initially, the value _ is an absolute pathname of the shell or
script being executed as passed in the environment.
Subsequently it is assigned the last argument of the previous
command. This parameter is not set for commands which are
asynchronous. This parameter is also used to hold the name of
the matching MAIL file when checking for mail.
! The process number of the last background command invoked.
ERRNO The value of errno as set by the most recently failed system
call. This value is system dependent and is intended for
debugging purposes.
LINENO The line number of the current line within the script or
function being executed.
OLDPWD The previous working directory set by the cd command.
OPTARG The value of the last option argument processed by the getopts
special command.
Page 7
sh(1) sh(1)
OPTIND The index of the last option argument processed by the getopts
special command.
PPID The process number of the parent of the shell.
PWD The present working directory set by the cd command.
RANDOM Each time this variable is referenced, a random integer,
uniformly distributed between 0 and 32767, is generated. The
sequence of random numbers can be initialized by assigning a
numeric value to RANDOM.
REPLY This variable is set by the select statement and by the read
special command when no arguments are supplied.
SECONDS Each time this variable is referenced, the number of seconds
since shell invocation is returned. If this variable is
assigned a value, the value returned upon reference is the value
that was assigned plus the number of seconds since the
assignment.
The following variables are used by the shell:
CDPATH The search path for the cd command.
COLUMNS If this variable is set, the value is used to define the
width of the edit window for the shell edit modes and for
printing select lists.
EDITOR If the value of this variable ends in emacs, or vi and the
VISUAL variable is not set, the corresponding option (see
special command set below) is turned on.
ENV If this variable is set, parameter substitution is performed
on the value to generate the pathname of the script that will
be executed when the shell is invoked (see Invocation below).
This file is typically used for alias and function
definitions.
FCEDIT The default editor name for the fc command.
FPATH The search path for function definitions. This path is
searched when a function with the -u attribute is referenced
and when a command is not found. If an executable file is
found, it is read and executed in the current environment.
IFS Internal field separators (normally space, tab, and newline)
used to separate command words that result from command or
parameter substitution and for separating words with the
special command read. The first character of the IFS
variable is used to separate arguments for the "$*"
substitution (see Quoting below).
Page 8
sh(1) sh(1)
HISTFILE If this variable is set when the shell is invoked, the value
is the pathname of the file that is used to store the command
history (see Command re-entry below).
HISTSIZE If this variable is set when the shell is invoked, the number
of previously entered commands that are accessible by this
shell is greater than or equal to this number. The default
is 128.
HOME The default argument (home directory) for the cd command.
LINES If this variable is set, the value is used to determine the
column length for printing select lists. Select lists print
vertically until about two-thirds of LINES lines are filled.
MAIL If this variable is set to the name of a mail file and the
MAILPATH variable is not set, the shell informs the user of
arrival of mail in the specified file.
MAILCHECK This variable specifies how often (in seconds) the shell
checks for changes in the modification time of any of the
files specified by the MAILPATH or MAIL variables. The
default value is 600 seconds. When the time has elapsed, the
shell checks before issuing the next prompt.
MAILPATH A colon ( : ) separated list of filenames. If this variable
is set the shell informs the user of any modifications to the
specified files that have occurred within the last MAILCHECK
seconds. Each filename can be followed by a ? and a message
that is printed. The message undergoes parameter
substitution with the variable, $_ defined as the name of the
file that has changed. The default message is you have mail
in $_.
PATH The search path for commands (see Execution below). The user
may not change PATH if executing under rsh (except in
.profile).
PS1 The value of this variable is expanded for parameter
substitution to define the primary prompt string which by
default is ``$ ''. The character ! in the primary prompt
string is replaced by the command number (see Command Reentry
below).
PS2 Secondary prompt string, by default ``> ''.
PS3 Selection prompt string used within a select loop, by default
``#? ''.
PS4 The value of this variable is expanded for parameter
substitution and precedes each line of an execution trace.
If omitted, the execution trace prompt is ``+ ''.
Page 9
sh(1) sh(1)
SHELL The pathname of the shell is kept in the environment. At
invocation, if the basename of this variable matches the
pattern *r*sh, the shell becomes restricted.
TMOUT If set to a value greater than zero, the shell terminates if
a command is not entered within the prescribed number of
seconds after issuing the PS1 prompt. (Note that the shell
can be compiled with a maximum bound for this value which
cannot be exceeded.)
VISUAL If the value of this variable ends in emacs, or vi the
corresponding option (see special command set below) is
turned on.
_XPG The value of this variable controls certain features of the
shell. The default value is 0 (zero). (See the COMPATIBILITY
ISSUES section at the end of this document)
The shell gives default values to PATH, PS1, PS2, MAILCHECK, _XPG, TMOUT
and IFS. HOME, MAIL and SHELL are set by login(1).
Blank Interpretation [Toc] [Back]
After parameter and command substitution, the results of substitutions
are scanned for the field separator characters ( those found in IFS ) and
split into distinct arguments where such characters are found. Explicit
null arguments ("" or '') are retained. Implicit null arguments (those
resulting from parameters that have no values) are removed.
Filename Generation [Toc] [Back]
Following substitution, each command word is scanned for the characters
*, ?, and [ unless the -f option has been set. If one of these
characters appears, the word is regarded as a pattern. The word is
replaced with lexicographically sorted filenames that match the pattern.
If no filename is found that matches the pattern, the word is left
unchanged. When a pattern is used for filename generation, the character
. at the start of a filename or immediately following a /, as well as
the character / itself, must be matched explicitly. In other instances
of pattern matching the / and . are not treated specially.
* Matches any string, including the null string.
? Matches any single character.
[...] Matches any one of the enclosed characters. A pair of characters
separated by - matches any character lexically between the pair,
inclusive. If the first character following the opening "[ " is
a "!" any character not enclosed is matched. A - can be included
in the character set by putting it as the first or last
character.
Page 10
sh(1) sh(1)
A pattern-list is a list of one or more patterns separated from each
other with a |. Composite patterns can be formed with one or more of the
following:
?(pattern-list<b>) Optionally matches any one of the given patterns.
*(pattern-list<b>) Matches zero or more occurrences of the given patterns.
+(pattern-list<b>) Matches one or more occurrences of the given patterns.
@(pattern-list<b>) Matches exactly one of the given patterns.
!(pattern-list<b>) Matches anything, except one of the given patterns.
Quoting [Toc] [Back]
Each of the metacharacters listed above (see Definitions above) has a
special meaning to the shell and causes termination of a word unless
quoted. A character may be quoted (that is, made to stand for itself) by
preceding it with a \. The pair \newline is removed. All characters
enclosed between a pair of single quote marks (''), are quoted. A single
quote cannot appear within single quotes. Inside double quote marks
(""), parameter and command substitution occurs and \ quotes the
characters \, `, ", and $. The meaning of $* and $@ is identical when
not quoted or when used as a variable assignment value or as a filename.
However, when used as a command argument, "$*" is equivalent to
"$1d<b>$2d...", where d is the first character of the IFS variable, whereas
"$@" is equivalent to "$1"d<b>"$2"d<b>... . Inside grave quote marks (``) \
quotes the characters \, `, and $. If the grave quotes occur within
double quotes, \ also quotes the character ".
The special meaning of reserved words or aliases can be removed by
quoting any character of the reserved word. The recognition of function
names or special command names listed below cannot be altered by quoting
them.
Arithmetic Evaluation [Toc] [Back]
An ability to perform integer arithmetic is provided with the special
command let. Evaluations are performed using long arithmetic. Constants
are of the form [base<b>#]n where base is a decimal number between two and
thirty-six representing the arithmetic base and n is a number in that
base. If base<b># is omitted base 10 is used.
An arithmetic expression uses the same syntax, precedence, and
associativity of expression of the C language. All the integral
operators, other than ++, --, ?:, and , are supported. Variables can be
referenced by name within an arithmetic expression without using the
parameter substitution syntax. When a variable is referenced, its value
is evaluated as an arithmetic expression.
An internal integer representation of a variable can be specified with
the -i option of the typeset special command. Arithmetic evaluation is
performed on the value of each assignment to a variable with the -i
Page 11
sh(1) sh(1)
attribute. If you do not specify an arithmetic base, the first
assignment to the variable determines the arithmetic base. This base is
used when parameter substitution occurs.
Since many of the arithmetic operators require quoting, an alternative
form of the let command is provided. For any command which begins with a
((, all the characters until a matching )) are treated as a quoted
expression. More precisely, ((...)) is equivalent to let "...".
Prompting [Toc] [Back]
When used interactively, the shell prompts with the parameter expanded
value of PS1 before reading a command. If at any time a newline is typed
and further input is needed to complete a command, the secondary prompt
(that is, the value of PS2) is issued.
Conditional Expressions [Toc] [Back]
A conditional expression is used with the [[ compound command to test
attributes of files and to compare strings. Word splitting and filename
generation are not performed on the words between [[ and ]]. Each
expression can be constructed from one or more of the following unary or
binary expressions:
-a file True, if file exists.
-b file True, if file exists and is a block special file.
-c file True, if file exists and is a character special file.
-d file True, if file exists and is a directory.
-e file Same as -a file.
-f file True, if file exists and is an ordinary file.
-g file True, if file exists and is has its setgid bit set.
-k file True, if file exists and is has its sticky bit set.
-n string True, if length of string is nonzero.
-o option True, if option named option is on.
-p file True, if file exists and is a fifo special file or a
pipe.
-r file True, if file exists and is readable by current
process.
-s file True, if file exists and has size greater than zero.
-t fildes True, if file descriptor number fildes is open and
associated with a terminal device.
-u file True, if file exists and is has its setuid bit set.
-w file True, if file exists and is writable by current
process.
-x file True, if file exists and is executable by current
process. If file exists and is a directory, the
current process has permission to search in the
directory.
-z string True, if length of string is zero.
-L file True, if file exists and is a symbolic link.
-O file True, if file exists and is owned by the effective
user id of this process.
Page 12
sh(1) sh(1)
-G file True, if file exists and its group matches the
effective group id of this process.
-S file True, if file exists and is a socket.
file1 <b>-nt file2 True, if file1 exists and is newer than file2.
file1 <b>-ot file2 True, if file1 exists and is older than file2.
file1 <b>-ef file2 True, if file1 and file2 exist and refer to the same
file.
string <b>= pattern True, if string matches pattern.
string <b>!= pattern True, if string does not match pattern.
string1 <b>< string2 True, if string1 comes before string2 based on ASCII
value of their characters.
string1 <b>> string2 True, if string1 comes after string2 based on ASCII
value of their characters.
exp1 <b>-eq exp2 True, if exp1 is equal to exp2.
exp1 <b>-ne exp2 True, if exp1 is not equal to exp2.
exp1 <b>-lt exp2 True, if exp1 is less than exp2.
exp1 <b>-gt exp2 True, if exp1 is greater than exp2.
exp1 <b>-le exp2 True, if exp1 is less than or equal to exp2.
exp1 <b>-ge exp2 True, if exp1 is greater than or equal to exp2.
In each of the above expressions, if file is of the form /dev/fd/n, where
n is an integer, the test is applied to the open file whose descriptor
number is n.
A compound expression can be constructed from these primitives by using
any of the following, listed in decreasing order of precedence.
(expression<b>) True, if expression is true. Used to group
expressions.
! expression True if expression is false.
expression1 <b>&& expression2 True, if expression1 and expression2 are
both true.
expression1 <b>|| expression2 True, if either expression1 or expression2
is true.
Input/Output
Before a command is executed, its input and output may be redirected
using a special notation interpreted by the shell. The following may
appear anywhere in a simple-command or may precede or follow a command
and are not passed on to the invoked command. Command and parameter
substitution occurs before word or digit is used except as noted below.
Filename generation occurs only if the pattern matches a single file and
blank interpretation is not performed.
<word Use file word as standard input (file descriptor 0).
>word Use file word as standard output (file descriptor 1). If the
file does not exist it is created. If the file exists, is a
regular file, and the noclobber option is on, this causes an
Page 13
sh(1) sh(1)
error; otherwise, it is truncated to zero length.
>|word Sames as >, except that it overrides the noclobber option.
>>word Use file word as standard output. If the file exists output
is appended to it (by first seeking to the end-of-file);
otherwise, the file is created.
<>word Open file word for reading and writing as standard input.
<<[-]word The shell input is read up to a line that is the same as
word, or to an end-of-file. No parameter substitution,
command substitution or filename generation is performed on
word. The resulting document, called a here-document,
becomes the standard input. If any character of word is
quoted, no interpretation is placed upon the characters of
the document; otherwise, parameter and command substitution
occurs, \newline is ignored, and \ must be used to quote the
characters \, $, `, and the first character of word. If - is
appended to <<, all leading tabs are stripped from word and
from the document.
<&digit The standard input is duplicated from file descriptor digit
[see dup(2)]. Similarly for the standard output using >&
digit.
<&- The standard input is closed. Similarly for the standard
output using >&-.
<&p The input from the co-process is moved to standard input.
>&p The output to the co-process is moved to standard output.
If one of the above is preceded by a digit, the file descriptor number
referred to is that specified by the digit (instead of the default 0 or
1). For example,
... 2>&1
means file descriptor 2 is to be opened for writing as a duplicate of
file descriptor 1.
The order in which redirections are specified is significant. The shell
evaluates each redirection in terms of the (file descriptor, file)
association at the time of evaluation. For example:
... 1>fname <b>2>&1
first associates file descriptor 1 with file fname. It then associates
file descriptor 2 with the file associated with file descriptor 1 (that
is, fname). If the order of redirections were reversed, file descriptor
2 is associated with the terminal (assuming file descriptor 1 had been)
<
|