Annotation of cci/usr/src/man/man1/sh.1, revision 1.1.1.1

1.1       root        1: .TH SH 1 "7 February 1983"
                      2: .SH NAME
                      3: sh, for, case, if, while, \fB:\fP, \fB.\fP, break, continue, cd, eval, exec, exit, export, login, read, readonly, set, shift, times, trap, umask, wait \- command language
                      4: .SH SYNOPSIS
                      5: .B sh
                      6: [
                      7: .B \-ceiknrstuvx
                      8: ] [ arg ] ...
                      9: .ds OK [\|
                     10: .ds CK \|]
                     11: .ds LT \s-2<\s0
                     12: .ds GT \s-2>\s0
                     13: .ds LE \s-2<\s0
                     14: .ds ST *
                     15: .SH DESCRIPTION
                     16: .I Sh
                     17: is a command programming language that executes commands read from a terminal
                     18: or a file.  See
                     19: .B invocation
                     20: for the meaning of arguments to the shell.
                     21: .PP
                     22: .B Commands.
                     23: .br
                     24: A
                     25: .I simple-command
                     26: is a sequence of non blank
                     27: .I words
                     28: separated by blanks (a blank is a
                     29: .B tab
                     30: or a
                     31: .BR space ).
                     32: The first word specifies the name of the command to be executed.
                     33: Except as specified below the remaining words are passed as arguments
                     34: to the invoked command.
                     35: The command name is passed as argument 0 (see
                     36: .IR execve (2)).
                     37: The
                     38: .I value
                     39: of a simple-command is its exit status
                     40: if it terminates normally or 200+\fIstatus\fP if it terminates abnormally (see
                     41: .IR sigvec (2)
                     42: for a list of status values).
                     43: .LP
                     44: A
                     45: .I pipeline
                     46: is a sequence of one or more
                     47: .I commands
                     48: separated by
                     49: .B \(or.
                     50: The standard output of each command but the last is connected by a
                     51: .IR pipe (2)
                     52: to the standard input of the next command.
                     53: Each command is run as a separate process;
                     54: the shell waits for the last command to terminate.
                     55: .LP
                     56: A
                     57: .I list
                     58: is a sequence of one or more
                     59: .I pipelines
                     60: separated by
                     61: .BR ; ,
                     62: .BR & ,
                     63: .B &&
                     64: or
                     65: .B \(or\|\(or
                     66: and optionally terminated by
                     67: .B ;
                     68: or
                     69: .BR & .
                     70: .B ;
                     71: and
                     72: .B &
                     73: have equal precedence which is lower than that of
                     74: .B &&
                     75: and
                     76: .BR \(or\|\(or ,
                     77: .B &&
                     78: and
                     79: .B \(or\|\(or
                     80: also have equal precedence.
                     81: A semicolon causes sequential execution; an ampersand causes the preceding
                     82: .I pipeline
                     83: to be executed without waiting for it to finish.  The symbol
                     84: .B &&
                     85: .RB ( \(or\|\(or )
                     86: causes the
                     87: .I list
                     88: following to be executed only if the preceding
                     89: .I pipeline
                     90: returns a zero (non zero) value.  Newlines may appear in a
                     91: .I list,
                     92: instead of semicolons, to delimit commands.
                     93: .LP
                     94: A
                     95: .I command
                     96: is either a simple-command or one of the following.
                     97: The value returned by a command is that of the
                     98: last simple-command executed in the command.
                     99: .TP
                    100: \fBfor \fIname\fR \*(OK\fBin \fIword\fR ...\*(CK \fBdo \fIlist \fBdone\fR
                    101: Each time a
                    102: .B for
                    103: command is executed
                    104: .I name
                    105: is set to the next word in the
                    106: .B for
                    107: word list
                    108: If
                    109: .BI in \ word
                    110: \&...
                    111: is omitted,
                    112: .B
                    113: in "$@"
                    114: is assumed.  Execution ends when there are no more words in the list.
                    115: .TP
                    116: \fBcase \fIword \fBin\fR \*(OK\fIpattern \fR\*(OK \fB\(or \fIpattern \fR\*(CK ... \fB) \fIlist \fB;;\fR\*(CK ... \fBesac\fR
                    117: A
                    118: .B case
                    119: command executes the
                    120: .I list
                    121: associated with the first pattern that matches
                    122: .I word.
                    123: The form of the patterns is the same as that used for file name generation.
                    124: .TP
                    125: \fBif \fIlist \fBthen \fIlist\fR \*(OK\fBelif \fIlist \fBthen \fIlist\fR\*(CK ... \*(OK\fBelse \fIlist\fR\*(CK \fBfi\fR
                    126: The
                    127: .I list
                    128: following
                    129: .B if
                    130: is executed and if it returns zero the
                    131: .I list
                    132: following
                    133: .B then
                    134: is executed.  Otherwise, the
                    135: .I list
                    136: following
                    137: .B elif
                    138: is executed and if its value is zero the
                    139: .I list
                    140: following
                    141: .B then
                    142: is executed.  Failing that the
                    143: .B else
                    144: .I list
                    145: is executed.
                    146: .TP
                    147: \fBwhile \fIlist\fR \*(OK\fBdo \fIlist\fR\*(CK \fBdone\fR
                    148: A
                    149: .B while
                    150: command repeatedly executes the
                    151: .B while
                    152: .I list
                    153: and if its value is zero executes the
                    154: .B do
                    155: .I list;
                    156: otherwise the loop terminates.  The value returned by a
                    157: .B while
                    158: command is that of the last executed command in the
                    159: .B do
                    160: .I list.
                    161: .B until
                    162: may be used in place of
                    163: .B while
                    164: to negate the loop termination test.
                    165: .TP
                    166: .BI ( " list " )
                    167: Execute
                    168: .I list
                    169: in a subshell.
                    170: .TP
                    171: .BI { " list " }
                    172: .I list
                    173: is simply executed.
                    174: .LP
                    175: The following words are only recognized as the first word of a command
                    176: and when not quoted.
                    177: .IP
                    178: .B
                    179: if then else elif fi case in esac for while until do done { }
                    180: .PP
                    181: .B Command substitution.
                    182: .br
                    183: The standard output from a command enclosed in a pair of back quotes 
                    184: .RB ( \`\|\` )
                    185: may be used as part or all of a word; trailing newlines are removed.
                    186: .PP
                    187: .B Parameter substitution.
                    188: .br
                    189: The character
                    190: .B $
                    191: is used to introduce substitutable parameters.
                    192: Positional parameters may be assigned values by
                    193: .BR set .
                    194: Variables may be set by writing
                    195: .IP
                    196: .IB name = value
                    197: [
                    198: .IB name = value
                    199: ] ...
                    200: .TP
                    201: $\fB\|{\fIparameter\fB\|}\fR
                    202: A
                    203: .I parameter
                    204: is a sequence of letters, digits or underscores (a
                    205: .IR name ),
                    206: a digit, or any of the characters
                    207: .B
                    208: * @ # ? \- $ !\|.
                    209: The value, if any, of the parameter is substituted.
                    210: The braces are required only when
                    211: .I parameter
                    212: is followed by a letter, digit, or underscore
                    213: that is not to be interpreted as part of its name.  If
                    214: .I parameter
                    215: is a digit, it is a positional parameter.  If
                    216: .I parameter
                    217: is
                    218: .BR * " or" " @"
                    219: then all the positional parameters, starting with
                    220: .SM
                    221: .BR $1 ,
                    222: are substituted separated by spaces.
                    223: .SM
                    224: .B $0
                    225: is set from argument zero when the shell is invoked.
                    226: .TP
                    227: $\fB\|{\fIparameter\|\-word\|\fB}\fR
                    228: If
                    229: .I parameter
                    230: is set, substitute its value; otherwise substitute
                    231: .I word.
                    232: .TP
                    233: $\fB\|{\fIparameter\|\(eq\|word\|\fB}\fR
                    234: If
                    235: .I parameter
                    236: is not set, set it to
                    237: .I word;
                    238: the value of the parameter is then substituted.
                    239: Positional parameters may not be assigned to in this way.
                    240: .TP
                    241: $\fB\|{\fIparameter\|?\|word\|\fB}\fR
                    242: If
                    243: .I parameter
                    244: is set, substitute its value; otherwise, print
                    245: .I word
                    246: and exit from the shell.  If
                    247: .I word
                    248: is omitted, a standard message is printed.
                    249: .TP
                    250: $\fB\|{\fIparameter\|\(plword\|\fB}\fR
                    251: If
                    252: .I parameter
                    253: is set, substitute
                    254: .I word;
                    255: otherwise substitute nothing.
                    256: .LP
                    257: In the above
                    258: .I word
                    259: is not evaluated unless it is to be used as the substituted string.
                    260: (So that, for example, echo ${d\-\'pwd\'} will only execute
                    261: .I pwd
                    262: if
                    263: .I d
                    264: is unset.)
                    265: .LP
                    266: The following
                    267: .I parameters
                    268: are automatically set by the shell.
                    269: .RS
                    270: .TP
                    271: .B #
                    272: The number of positional parameters in decimal.
                    273: .PD 0
                    274: .TP
                    275: .B \-
                    276: Options supplied to the shell on invocation or by
                    277: .BR set .
                    278: .TP
                    279: .B ?
                    280: The value returned by the last executed command in decimal.
                    281: .TP
                    282: .B $
                    283: The process number of this shell.
                    284: .TP
                    285: .B !
                    286: The process number of the last background command invoked.
                    287: .PD
                    288: .RE
                    289: .LP
                    290: The following
                    291: .I parameters
                    292: are used but not set by the shell.
                    293: .RS
                    294: .TP
                    295: .B
                    296: .SM HOME
                    297: The default argument (home directory) for the
                    298: .B cd
                    299: command.
                    300: .PD 0
                    301: .TP
                    302: .B
                    303: .SM PATH
                    304: The search path for commands (see
                    305: .BR execution ).
                    306: .TP
                    307: .B
                    308: .SM MAIL
                    309: If this variable is set to the name of
                    310: a mail file, the shell informs the user of
                    311: the arrival of mail in the specified file.
                    312: .SM
                    313: .TP
                    314: .B PS1
                    315: Primary prompt string, by default '$ '.
                    316: .TP
                    317: .SM
                    318: .B PS2
                    319: Secondary prompt string, by default '> '.
                    320: .TP
                    321: .SM
                    322: .B IFS
                    323: Internal field separators, normally
                    324: .BR space ,
                    325: .BR tab ,
                    326: and
                    327: .BR newline .
                    328: .PD
                    329: .RE
                    330: .PP
                    331: .B Blank interpretation.
                    332: .br
                    333: After parameter and command substitution,
                    334: any results of substitution are scanned for internal field separator
                    335: characters (those found in
                    336: .SM
                    337: .BR $IFS \*S)
                    338: and split into distinct arguments where such characters are found.
                    339: Explicit null arguments ("" or \'\') are retained.
                    340: Implicit null arguments (those resulting from
                    341: .I parameters
                    342: that have no values) are removed.
                    343: .PP
                    344: .B File name generation.
                    345: .br
                    346: Following substitution, each command word is scanned for the characters
                    347: .BR * ,
                    348: .B ?
                    349: and
                    350: .B \*(OK.
                    351: If one of these characters appears, the word is regarded as a pattern.
                    352: The word is replaced with alphabetically sorted file names that match the
                    353: pattern.  If no file name is found that matches the pattern,
                    354: the word is left unchanged.  The character
                    355: .B .
                    356: at the start of a file name or immediately following a
                    357: .BR / ,
                    358: and the character
                    359: .BR / ,
                    360: must be matched explicitly.
                    361: .TP 
                    362: .B \*(ST
                    363: Matches any string, including the null string.
                    364: .PD 0
                    365: .TP 
                    366: .B ?
                    367: Matches any single character.
                    368: .TP 
                    369: .B \*(OK...\*(CK
                    370: Matches any one of the characters enclosed.
                    371: A pair of characters separated by
                    372: .B \-
                    373: matches any character lexically between the pair.
                    374: .PD
                    375: .PP
                    376: .B Quoting.
                    377: .br
                    378: The following characters have a special meaning to the shell
                    379: and cause termination of a word unless quoted.
                    380: .LP
                    381:        \fB;   &   (   )   \(or   \*(LT   \*(GT   newline   space   tab\fP
                    382: .LP
                    383: A character may be
                    384: .I quoted
                    385: by preceding it with a
                    386: .B
                    387: \\\|.
                    388: .B \\\\newline
                    389: is ignored.
                    390: All characters enclosed between a pair of quote marks (\fB\'\|\'\fP),
                    391: except a single quote, are quoted.  Inside double quotes (\fB"\|"\fP)
                    392: parameter and command substitution occurs and
                    393: .B
                    394: \\
                    395: quotes the characters
                    396: .B
                    397: \\ \' "
                    398: and
                    399: .BR $ \|.
                    400: .LP
                    401: .B
                    402: "$*"
                    403: is equivalent to
                    404: .SM
                    405: .B
                    406: "$1 $2 ..."
                    407: whereas
                    408: .br
                    409: .B
                    410: "$@"
                    411: is equivalent to
                    412: .SM
                    413: .B
                    414: "$1" "$2" ... .
                    415: .PP
                    416: .B Prompting.
                    417: .br
                    418: When used interactively, the shell prompts with the value of
                    419: .SM
                    420: PS1
                    421: before reading a command.
                    422: If at any time a newline is typed and further input is needed
                    423: to complete a command, the secondary prompt
                    424: .RB ( \s-2$PS2\s0 )
                    425: is issued.
                    426: .PP
                    427: .B Input output.
                    428: .br
                    429: Before a command is executed its input and output
                    430: may be redirected using a special notation interpreted by the shell.
                    431: The following may appear anywhere in a simple-command
                    432: or may precede or follow a
                    433: .I command
                    434: and are not passed on to the invoked command.
                    435: Substitution occurs before
                    436: .I word
                    437: or
                    438: .I digit
                    439: is used.
                    440: .TP
                    441: \*(LT\fI\|word\fP
                    442: Use file
                    443: .I word
                    444: as standard input (file descriptor 0).
                    445: .PD
                    446: .TP
                    447: \*(GT\fI\|word\fP
                    448: Use file
                    449: .I word
                    450: as standard output (file descriptor 1).
                    451: If the file does not exist, it is created;
                    452: otherwise it is truncated to zero length.
                    453: .TP
                    454: \*(GT\*(GT\fI\|word\fP
                    455: Use file
                    456: .I word
                    457: as standard output.
                    458: If the file exists, output is appended (by seeking to the end);
                    459: otherwise the file is created.
                    460: .TP
                    461: \*(LT\*(LT\fI\|word\fP
                    462: The shell input is read up to a line the same as
                    463: .IR word ,
                    464: or end of file.
                    465: The resulting document becomes the standard input.
                    466: If any character of
                    467: .I word
                    468: is quoted, no interpretation is placed upon the characters of the document;
                    469: otherwise, parameter and command substitution occurs,
                    470: .B
                    471: \\newline
                    472: is ignored, and
                    473: .B
                    474: \\
                    475: is used to quote the characters
                    476: .B
                    477: \\ $ \'
                    478: and the first character of
                    479: .I word.
                    480: .TP
                    481: \*(LT\|&\|\fIdigit\fP
                    482: The standard input is duplicated from file descriptor
                    483: .I digit;
                    484: see
                    485: .IR dup (2).
                    486: Similarly for the standard output using \*(GT\|.
                    487: .TP
                    488: \*(LT\|&\|\-
                    489: The standard input is closed.
                    490: Similarly for the standard output using \*(GT\|.
                    491: .PD
                    492: .LP
                    493: If one of the above is preceded by a digit, the
                    494: file descriptor created is that specified by the digit
                    495: (instead of the default 0 or 1).  For example,
                    496: .LP
                    497:        \&... 2\*(GT&1
                    498: .LP
                    499: creates file descriptor 2 to be a duplicate
                    500: of file descriptor 1.
                    501: .LP
                    502: If a command is followed by
                    503: .B &
                    504: then the default standard input for the command is the empty file
                    505: (/dev/null).
                    506: Otherwise, the environment for the execution of a command contains the
                    507: file descriptors of the invoking shell as modified by input
                    508: output specifications.
                    509: .PP
                    510: .B Environment.
                    511: .br
                    512: The environment is a list of name-value pairs that is passed to
                    513: an executed program in the same way as a normal argument list; see
                    514: .IR execve (2)
                    515: and
                    516: .IR environ (7).
                    517: The shell interacts with the environment in several ways.
                    518: On invocation, the shell scans the environment and creates a
                    519: .I parameter
                    520: for each name found, giving it the corresponding value.
                    521: Executed commands inherit the same environment.
                    522: If the user modifies the values of these
                    523: .I parameters
                    524: or creates new ones, none of these affects the environment unless the
                    525: .B export
                    526: command is used to bind the shell's
                    527: .I parameter
                    528: to the environment.
                    529: The environment seen by any executed command is thus composed
                    530: of any unmodified name-value pairs originally inherited by the shell,
                    531: plus any modifications or additions, all of which must be noted in
                    532: .B export
                    533: commands.
                    534: .LP
                    535: The environment for any
                    536: .I simple-command
                    537: may be augmented by prefixing it with one or more assignments to
                    538: .I parameters.
                    539: Thus these two lines are equivalent
                    540: .IP
                    541: TERM=450 cmd args
                    542: .br
                    543: (export TERM; TERM=450; cmd args)
                    544: .LP
                    545: If the
                    546: .B \-k
                    547: flag is set,
                    548: .I all
                    549: keyword arguments are placed in the environment,
                    550: even if the occur after the command name.
                    551: The following prints 'a=b c' and 'c':
                    552: .nf
                    553: echo a=b c
                    554: set \-k
                    555: echo a=b c
                    556: .fi
                    557: .PP
                    558: .B Signals.
                    559: .br
                    560: The INTERRUPT and QUIT signals for an invoked
                    561: command are ignored if the command is followed by
                    562: .BR & ;
                    563: otherwise signals have the values inherited by the shell from its parent.
                    564: (But see also
                    565: .BR trap. )
                    566: .PP
                    567: .B Execution.
                    568: .br
                    569: Each time a command is executed the above substitutions are carried out.
                    570: Except for the 'special commands' listed below a new process is created and
                    571: an attempt is made to execute the command via an
                    572: .IR execve (2).
                    573: .LP
                    574: The shell parameter
                    575: .B
                    576: .SM $PATH
                    577: defines the search path for the directory containing the command.
                    578: Each alternative directory name is separated by a colon
                    579: .RB ( : ).
                    580: The default path is
                    581: .BR :/bin:/usr/bin .
                    582: If the command name contains a /, the search path is not used.
                    583: Otherwise, each directory in the path is searched for an executable file.
                    584: If the file has execute permission but is not an
                    585: .I a.out
                    586: file, it is assumed to be a file containing shell commands.
                    587: A subshell (i.e., a separate process) is spawned to read it.
                    588: A parenthesized command is also executed in a subshell.
                    589: .PP
                    590: .B Special commands.
                    591: .br
                    592: The following commands are executed in the shell process
                    593: and except where specified
                    594: no input output redirection is permitted for such commands.
                    595: .TP
                    596: .B :
                    597: No effect; the command does nothing.
                    598: .PD 0
                    599: .TP
                    600: .BI . \ file
                    601: Read and execute commands from
                    602: .I file
                    603: and return.  The search path
                    604: .B
                    605: .SM $PATH
                    606: is used to find the directory containing
                    607: .IR file .
                    608: .TP
                    609: \fBbreak\fR \*(OK\fIn\fR\*(CK
                    610: Exit from the enclosing
                    611: .B for
                    612: or
                    613: .B while
                    614: loop, if any.
                    615: If
                    616: .I n
                    617: is specified, break
                    618: .I n
                    619: levels.
                    620: .TP
                    621: \fBcontinue\fR \*(OK\fIn\fR\*(CK
                    622: Resume the next iteration of the enclosing
                    623: .B for
                    624: or
                    625: .B while
                    626: loop.  If
                    627: .I n
                    628: is specified, resume at the
                    629: .IR n -th
                    630: enclosing loop.
                    631: .TP
                    632: \fBcd\fR \*(OK\fIarg\fR\*(CK
                    633: Change the current directory to
                    634: .I arg.
                    635: The shell parameter
                    636: .B
                    637: .SM $HOME
                    638: is the default
                    639: .IR arg .
                    640: .TP
                    641: \fBeval\fR \*(OK\fIarg \fR...\*(CK
                    642: The arguments are read as input to the shell
                    643: and the resulting command(s) executed.
                    644: .TP
                    645: \fBexec\fR \*(OK\fIarg \fR...\*(CK
                    646: The command specified by the arguments is executed in place of this shell
                    647: without creating a new process.
                    648: Input output arguments may appear and if no other
                    649: arguments are given cause the shell input output to be modified.
                    650: .TP
                    651: \fBexit\fR \*(OK\fIn\fR\*(CK
                    652: Causes a non interactive shell to exit with the exit status specified by
                    653: .I n.
                    654: If
                    655: .I n
                    656: is omitted, the exit status is that of the last command executed.
                    657: (An end of file will also exit from the shell.)
                    658: .TP
                    659: \fBexport\fR \*(OK\fIname\fR ...\*(CK
                    660: The given names are marked for automatic export to the
                    661: .I environment
                    662: of subsequently-executed commands.
                    663: If no arguments are given, a list of exportable names is printed.
                    664: .TP
                    665: \fBlogin\fR \*(OK\fIarg\fR ...\*(CK
                    666: Equivalent to 'exec login arg ...'.
                    667: .TP
                    668: .BI read \ name\ ...
                    669: One line is read from the standard input;
                    670: successive words of the input are assigned to the variables
                    671: .I name
                    672: in order, with leftover words to the last variable.
                    673: The return code is 0 unless the end-of-file is encountered.
                    674: .TP
                    675: \fBreadonly\fR \*(OK\fIname \fR...\*(CK
                    676: The given names are marked readonly and
                    677: the values of the these names may not be changed
                    678: by subsequent assignment.
                    679: If no arguments are given, a list of all readonly names is printed.
                    680: .TP
                    681: \fBset\fR \*(OK\fB\-eknptuvx\fR \*(OK\fIarg \fR...\*(CK\*(CK
                    682: .RS
                    683: .PD 0
                    684: .TP 3m
                    685: .B \-e
                    686: If non interactive, exit immediately if a command fails.
                    687: .TP
                    688: .B \-k
                    689: All keyword arguments are placed in the environment for a command,
                    690: not just those that precede the command name.
                    691: .TP
                    692: .B \-n
                    693: Read commands but do not execute them.
                    694: .TP
                    695: .B \-t
                    696: Exit after reading and executing one command.
                    697: .TP
                    698: .B \-u
                    699: Treat unset variables as an error when substituting.
                    700: .TP
                    701: .B \-v
                    702: Print shell input lines as they are read.
                    703: .TP
                    704: .B \-x
                    705: Print commands and their arguments as they are executed.
                    706: .TP
                    707: .B \-
                    708: Turn off the
                    709: .B \-x
                    710: and
                    711: .B \-v
                    712: options.
                    713: .PD
                    714: .LP
                    715: These flags can also be used upon invocation of the shell.
                    716: The current set of flags may be found in
                    717: .BR $\- .
                    718: .LP
                    719: Remaining arguments are positional
                    720: parameters and are assigned, in order, to
                    721: .SM
                    722: .BR $1 ,
                    723: .SM
                    724: .BR $2 ,
                    725: etc.  If no arguments are given, the values of all names are printed.
                    726: .RE
                    727: .TP
                    728: .B shift
                    729: The positional parameters from
                    730: .SM
                    731: .BR $2 ...
                    732: are renamed
                    733: .SM
                    734: .BRhead     1.1;
                    735: access   ;
                    736: symbols  ;
                    737: locks    root:1.1; strict;
                    738: comment  @;
                    739: 
                    740: 
                    741: 1.1
                    742: date     84.06.21.14.05.41;  author root;  state Exp;
                    743: branches ;
                    744: next     ;
                    745: 
                    746: 
                    747: desc

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.