144281Scael.\" Copyright (c) 1990 Regents of the University of California. 244281Scael.\" All rights reserved. The Berkeley software License Agreement 344281Scael.\" specifies the terms and conditions for redistribution. 419463Smckusick.\" 5*44957Scael.\" @(#)sh.1 6.6 (Berkeley) 07/24/90 643084Scael.\" 743084Scael.Dd 843084Scael.Dt SH 1 943084Scael.Os ATT 7th 1043084Scael.Sh NAME 1143084Scael.Nm sh 1243084Scael.Nd shell command interpreter 1343084Scael.Sh SYNOPSIS 1443084Scael.Nm sh 1543084Scael.Op Fl ceiknrstuvx 1643084Scael.Op arg 1743084Scael.Ar ... 1843084Scael.Sh DESCRIPTION 1943084Scael.Nm Sh 2019464Smckusickis a command programming language that executes commands read from a terminal 2143084Scaelor a file. The shell this page describes is called the 2243084Scael.Em Bourne 2343084Scaelshell. 2443084Scael.Pp 2543084ScaelCommand line options: 2643084Scael.Pp 2743084ScaelIf the first character of argument 0 if 2843084Scael.Fl , 2943084Scaelcommands are read from 3043084Scael.Pa $HOME/.profile , 3143084Scaelif such a file exists. 3243084ScaelThe following flags are interpreted by the shell when it is invoked. 3343084Scael.Tw Fl 3443084Scael.Tp Cx Fl c 3543084Scael.Cx \&\ \& 3643084Scael.Ar string 3743084Scael.Cx 3843084ScaelCommands are read from 3943084Scael.Ar string. 4043084Scael.Tp Fl s 4143084ScaelIf the 4243084Scael.Fl s 4343084Scaelflag is present or if no arguments remain 4443084Scaelthen commands are read from the standard input. 4543084ScaelShell output is written to file descriptor 2. 4643084Scael.Tp Fl i 4743084ScaelIf the 4843084Scael.Fl i 4943084Scaelflag is present or 5043084Scaelif the shell input and output are attached to a terminal (as told by 5143084Scael.Xr getty ) 5243084Scaelthen this shell is 5343084Scael.Em interactive . 5443084ScaelIn this case the terminate signal SIGTERM (see 5543084Scael.Xr sigvec 2 ) 5643084Scaelis ignored (so that 'kill 0' 5743084Scaeldoes not kill an interactive shell) and the interrupt signal 5843084ScaelSIGINT is caught and ignored (so that 5943084Scael.Xr wait 6043084Scaelis interruptible). 6143084ScaelIn all cases SIGQUIT is ignored by the shell. 6243084Scael.Tp 6343084Scael.Pp 6443084ScaelThis next set of options can be used on the command line invoking 6543084Scaelthe 6643084Scael.Nm sh 6743084Scaelor set with the interactive command 6843084Scael.Ic set . 6943084Scael.Tp Fl e 7043084ScaelIf non interactive, exit immediately if a command fails. 7143084Scael.Tp Fl k 7243084ScaelAll keyword arguments are placed in the environment for a command, 7343084Scaelnot just those that precede the command name. 7443084Scael.Tp Fl n 7543084ScaelRead commands but do not execute them. 7643084Scael.Tp Fl t 7743084ScaelExit after reading and executing one command. 7843084Scael.Tp Fl u 7943084ScaelTreat unset variables as an error when substituting. 8043084Scael.Tp Fl v 8143084ScaelPrint shell input lines as they are read. 8243084Scael.Tp Fl x 8343084ScaelPrint commands and their arguments as they are executed. 8443084Scael.Tp Fl 8543084ScaelTurn off the 8643084Scael.Fl x 8743084Scaeland 8843084Scael.Fl v 8943084Scaeloptions. 9043084Scael.Tp 9143084Scael.Ss Commands . 9219463SmckusickA 9343084Scael.Em simple-command 9419463Smckusickis a sequence of non blank 9543084Scael.Em words 9619463Smckusickseparated by blanks (a blank is a 9743084Scael.Em tab 9819463Smckusickor a 9943084Scael.Em space ) . 10019464SmckusickThe first word specifies the name of the command to be executed. 10119464SmckusickExcept as specified below the remaining words are passed as arguments 10219463Smckusickto the invoked command. 10319464SmckusickThe command name is passed as argument 0 (see 10443084Scael.Xr execve 2 ) . 10519463SmckusickThe 10643084Scael.Em value 10719463Smckusickof a simple-command is its exit status 10843084Scaelif it terminates normally or 10943084Scael.Cx Li 200+ 11043084Scael.Em status 11143084Scael.Cx 11243084Scaelif it terminates abnormally (see 11343084Scael.Ar sigvec 2 11419464Smckusickfor a list of status values). 11543084Scael.Pp 11619463SmckusickA 11743084Scael.Em pipeline 11819463Smckusickis a sequence of one or more 11943084Scael.Em commands 12019463Smckusickseparated by 12143084Scael.Sq Nm \&| . 12219464SmckusickThe standard output of each command but the last is connected by a 12343084Scael.Xr pipe 2 12419463Smckusickto the standard input of the next command. 12519463SmckusickEach command is run as a separate process; 12619463Smckusickthe shell waits for the last command to terminate. 12743084Scael.Pp 12819463SmckusickA 12943084Scael.Em list 13019463Smckusickis a sequence of one or more 13143084Scael.Em pipelines 13219463Smckusickseparated by 13343084Scael.Nm \&; , 13443084Scael.Nm \&& , 13543084Scael.Nm \&&& 13619463Smckusickor 13743084Scael.Nm \&| 13843084Scaelor 13943084Scael.Nm \&|\&| 14019463Smckusickand optionally terminated by 14143084Scael.Nm \&; 14219463Smckusickor 14343084Scael.Nm \&& . 14443084Scael.Nm \&; 14519463Smckusickand 14643084Scael.Nm \&& 14719464Smckusickhave equal precedence which is lower than that of 14843084Scael.Nm \&&& 14919463Smckusickand 15043084Scael.Nm \&|\&| , 15143084Scael.Nm && 15219463Smckusickand 15343084Scael.Nm \&|\&| , 15419463Smckusickalso have equal precedence. 15519464SmckusickA semicolon causes sequential execution; an ampersand causes the preceding 15643084Scael.Em pipeline 15719464Smckusickto be executed without waiting for it to finish. The symbol 15843084Scael.Nm \&&& 15943084Scael.Pq Nm \&|\&| 16019463Smckusickcauses the 16143084Scael.Em list 16219463Smckusickfollowing to be executed only if the preceding 16343084Scael.Em pipeline 16419464Smckusickreturns a zero (non zero) value. Newlines may appear in a 16543084Scael.Em list , 16619464Smckusickinstead of semicolons, to delimit commands. 16743084Scael.Pp 16819463SmckusickA 16943084Scael.Em command 17019464Smckusickis either a simple-command or one of the following. 17119463SmckusickThe value returned by a command is that of the 17219463Smckusicklast simple-command executed in the command. 17343084Scael.Tw Fl 17443084Scael.Tp Cx Ic for 17543084Scael.Cx \&\ \& 17643084Scael.Ar name 17743084Scael.Cx \&\ \& 17843084Scael.Op Ic in Ar word ... 17943084Scael.Cx \&\ \& 18043084Scael.Ic do 18143084Scael.Cx \&\ \& 18243084Scael.Ar list 18343084Scael.Cx \&\ \& 18443084Scael.Ic done 18543084Scael.Cx 18619463SmckusickEach time a 18743084Scael.Ic for 18819463Smckusickcommand is executed 18943084Scael.Ar name 19019463Smckusickis set to the next word in the 19143084Scael.Ic for 19227208Slepreauword list. 19319463SmckusickIf 19443084Scael.Ic in 19543084Scael.Ar word \&... 19619464Smckusickis omitted, 19743084Scael.Ic in 19843084Scael.Dq Ic \&$@ 19919464Smckusickis assumed. Execution ends when there are no more words in the list. 20043084Scael.Tp Cx Ic case 20143084Scael.Cx \&\ \& 20243084Scael.Ar word 20343084Scael.Cx \&\ \& 20443084Scael.Ic in 20543084Scael.Cx \&\ \&[ 20643084Scael.Ar pattern 20743084Scael.Cx \&\ \& 20843084Scael.Op Ar \&| pattern ... 20943084Scael.Cx \&\ \& 21043084Scael.Ic \&) 21143084Scael.Cx \&\ \& 21243084Scael.Ar list 21343084Scael.Cx \&\ \& 21443084Scael.Ic \&;; 21543084Scael.Cx \&]\ \& ... 21643084Scael.Ar esac 21743084Scael.Cx 21819463SmckusickA 21943084Scael.Ic case 22019463Smckusickcommand executes the 22143084Scael.Ar list 22219464Smckusickassociated with the first pattern that matches 22343084Scael.Ar word . 22419464SmckusickThe form of the patterns is the same as that used for file name generation. 22543084Scael.Tp Cx Ic if 22643084Scael.Cx \&\ \& 22743084Scael.Ar list 22843084Scael.Cx \&\ \& 22943084Scael.Ic then 23043084Scael.Cx \&\ \& 23143084Scael.Ar list 23243084Scael.Cx \&\ \& 23343084Scael.Op Ic elif Ar list Ic then Ar list 23443084Scael.Cx \&\ \& 23543084Scael.Cx \&... 23643084Scael.Cx \&\ \& 23743084Scael.Op Ic else Ar list 23843084Scael.Cx \&\ \& 23943084Scael.Ic fi 24043084Scael.Cx 24119463SmckusickThe 24243084Scael.Ar list 24319463Smckusickfollowing 24443084Scael.Ic if 24519463Smckusickis executed and if it returns zero the 24643084Scael.Ar list 24719463Smckusickfollowing 24843084Scael.Ic then 24919464Smckusickis executed. Otherwise, the 25043084Scael.Ar list 25119463Smckusickfollowing 25243084Scael.Ic elif 25319464Smckusickis executed and if its value is zero the 25443084Scael.Ar list 25519463Smckusickfollowing 25643084Scael.Ic then 25719464Smckusickis executed. Failing that the 25843084Scael.Ic else 25943084Scael.Ar list 26019463Smckusickis executed. 26143084Scael.Tp Cx Ic while 26243084Scael.Cx \&\ \& 26343084Scael.Ar list 26443084Scael.Cx \&\ \& 26543084Scael.Op Ic do Ar list 26643084Scael.Cx \&\ \& 26743084Scael.Ic done 26843084Scael.Cx 26919463SmckusickA 27043084Scael.Ic while 27119463Smckusickcommand repeatedly executes the 27243084Scael.Ic while 27343084Scael.Ar list 27419463Smckusickand if its value is zero executes the 27543084Scael.Ic do 27643084Scael.Ar list ; 27719464Smckusickotherwise the loop terminates. The value returned by a 27843084Scael.Ic while 27919464Smckusickcommand is that of the last executed command in the 28043084Scael.Ic do 28143084Scael.Ar list . 28243084Scael.Ic until 28319463Smckusickmay be used in place of 28443084Scael.Ic while 28519464Smckusickto negate the loop termination test. 28643084Scael.Tp Pq Ar list 28719463SmckusickExecute 28843084Scael.Ar list 28919463Smckusickin a subshell. 29043084Scael.Tp Cx \&{ 29143084Scael.Ar list 29243084Scael.Cx \&} 29343084Scael.Cx 29443084Scael.Ar list 29519463Smckusickis simply executed. 29643084Scael.Tp 29743084Scael.Pp 29819464SmckusickThe following words are only recognized as the first word of a command 29919463Smckusickand when not quoted. 30043084Scael.Df I 30143084Scael.Nm if then else elif fi case in esac 30243084Scael.Nm for while until do done \&{ \&} 30343084Scael.De 30443084Scael.Pp 30543084Scael.Ss Command substitution 30643084ScaelThe standard output from a command enclosed in a pair of back quotes 30743084Scael.Pq Ic \&`` 30819464Smckusickmay be used as part or all of a word; trailing newlines are removed. 30943084Scael.Pp 31043084Scael.Ss Parameter substitution . 31119463SmckusickThe character 31243084Scael.Ic \&$ 31319464Smckusickis used to introduce substitutable parameters. 31419463SmckusickPositional parameters may be assigned values by 31543084Scael.Ic set . 31619463SmckusickVariables may be set by writing 31743084Scael.Pp 31843084Scael.Df I 31943084Scael.Ar name=value 32043084Scael.Op Ar name=value 32143084Scael\&... 32243084Scael.De 32343084Scael.Pp 32443084Scael.Tp Cx Ic \&$ 32543084Scael.Cx \&\ \& 32643084Scael.Sy \&{ 32743084Scael.Ar parameter 32843084Scael.Sy \&} 32943084Scael.Cx 33019463SmckusickA 33143084Scael.Ar parameter 33219463Smckusickis a sequence of letters, digits or underscores (a 33343084Scael.Ar name ) , 33419464Smckusicka digit, or any of the characters 33543084Scael.Nm \&* \&@ \&# \&? \&\- \&$ \&!\ 33619463SmckusickThe value, if any, of the parameter is substituted. 33719463SmckusickThe braces are required only when 33843084Scael.Ar parameter 33919463Smckusickis followed by a letter, digit, or underscore 34019464Smckusickthat is not to be interpreted as part of its name. If 34143084Scael.Ar parameter 34219464Smckusickis a digit, it is a positional parameter. If 34343084Scael.Ar parameter 34419463Smckusickis 34543084Scael.Ic \&* 34643084Scaelor 34743084Scael.Ic \&@ 34819464Smckusickthen all the positional parameters, starting with 34943084Scael.Ic $1 , 35019464Smckusickare substituted separated by spaces. 35143084Scael.Ic $0 35219464Smckusickis set from argument zero when the shell is invoked. 35343084Scael.Tp Cx Ic \&$ 35443084Scael.Cx \&\ \& 35543084Scael.Sy \&{ 35643084Scael.Ar parameter 35743084Scael.Fl 35843084Scael.Ar word 35943084Scael.Sy \&} 36043084Scael.Cx 36119463SmckusickIf 36243084Scael.Ar parameter 36319464Smckusickis set, substitute its value; otherwise substitute 36443084Scael.Ar word . 36543084Scael.Tp Cx Ic \&$ 36643084Scael.Cx \&\ \& 36743084Scael.Sy \&{ 36843084Scael.Ar parameter 36943084Scael.Ic \&= 37043084Scael.Ar word 37143084Scael.Cx \&\ \& 37243084Scael.Sy \&} 37343084Scael.Cx 37419463SmckusickIf 37543084Scael.Ar parameter 37619464Smckusickis not set, set it to 37743084Scael.Ar word ; 37819463Smckusickthe value of the parameter is then substituted. 37919464SmckusickPositional parameters may not be assigned to in this way. 38043084Scael.Tp Cx Ic \&$ 38143084Scael.Cx \&\ \& 38243084Scael.Sy \&{ 38343084Scael.Ar parameter 38443084Scael.Ic \&? 38543084Scael.Ar word 38643084Scael.Sy \&} 38743084Scael.Cx 38819463SmckusickIf 38943084Scael.Ar parameter 39019464Smckusickis set, substitute its value; otherwise, print 39143084Scael.Ar word 39219464Smckusickand exit from the shell. If 39343084Scael.Ar word 39419464Smckusickis omitted, a standard message is printed. 39543084Scael.Tp Cx Ic \&$ 39643084Scael.Cx \&\ \& 39743084Scael.Sy \&{ 39843084Scael.Ar parameter 39943084Scael.Ic \&+ 40043084Scael.Ar word 40143084Scael.Sy \&} 40243084Scael.Cx 40319463SmckusickIf 40443084Scael.Ar parameter 40519464Smckusickis set, substitute 40643084Scael.Ar word ; 40719463Smckusickotherwise substitute nothing. 40843084Scael.Tp 40943084Scael.Pp 41019463SmckusickIn the above 41143084Scael.Ar word 41219464Smckusickis not evaluated unless it is to be used as the substituted string. 41319464Smckusick(So that, for example, echo ${d\-\'pwd\'} will only execute 41443084Scael.Ar pwd 41519463Smckusickif 41643084Scael.Ar d 41719463Smckusickis unset.) 41843084Scael.Pp 41919463SmckusickThe following 42043084Scael.Ar parameters 42119463Smckusickare automatically set by the shell. 42243084Scael.Pp 42343084Scael.Dw Ds 42443084Scael.Dp Ic \&# 42519463SmckusickThe number of positional parameters in decimal. 42643084Scael.Dp Fl 42719463SmckusickOptions supplied to the shell on invocation or by 42843084Scael.Ar set . 42943084Scael.Dp Ic \&? 43019464SmckusickThe value returned by the last executed command in decimal. 43143084Scael.Dp Ic \&$ 43219463SmckusickThe process number of this shell. 43343084Scael.Dp Ic \&! 43419463SmckusickThe process number of the last background command invoked. 43543084Scael.Dp 43643084Scael.De 43743084Scael.Pp 43819463SmckusickThe following 43943084Scael.Ar parameters 44019463Smckusickare used but not set by the shell. 44143084Scael.Pp 44243084Scael.Ds I 44343084Scael.Tp Ev HOME 44419463SmckusickThe default argument (home directory) for the 44543084Scael.Ic cd 44619463Smckusickcommand. 44743084Scael.Tp Ev PATH 44819463SmckusickThe search path for commands (see 44943084Scael.Ar execution ) . 45043084Scael.Tp Ev MAIL 45119463SmckusickIf this variable is set to the name of 45219464Smckusicka mail file, the shell informs the user of 45319463Smckusickthe arrival of mail in the specified file. 45443084Scael.Tp Ev PS1 45519464SmckusickPrimary prompt string, by default '$ '. 45643084Scael.Tp Ev PS2 45719464SmckusickSecondary prompt string, by default '> '. 45843084Scael.Tp Ev IFS 45919464SmckusickInternal field separators, normally 46043084Scael.Em space , 46143084Scael.Em tab , 46219463Smckusickand 46343084Scael.Em newline . 46443084Scael.Ev IFS 46543084Scaelis ignored if 46643084Scael.Nm sh 46727716Smckusickis running as root or if the effective user id differs from the real user id. 46843084Scael.Tp 46943084Scael.De 47043084Scael.Ss Blank interpretation . 47119463SmckusickAfter parameter and command substitution, 47219463Smckusickany results of substitution are scanned for internal field separator 47319463Smckusickcharacters (those found in 47443084Scael.Cx Ic $ 47543084Scael.Ev IFS ) 47643084Scael.Cx 47719463Smckusickand split into distinct arguments where such characters are found. 47819463SmckusickExplicit null arguments ("" or \'\') are retained. 47919464SmckusickImplicit null arguments (those resulting from 48043084Scael.Em parameters 48119463Smckusickthat have no values) are removed. 48243084Scael.Pp 48343084Scael.Ss File name generation . 48419464SmckusickFollowing substitution, each command word is scanned for the characters 48543084Scael.Ic \&* , 48643084Scael.Ic \&? 48719463Smckusickand 48843084Scael.Ic \&[ . 48919464SmckusickIf one of these characters appears, the word is regarded as a pattern. 49019464SmckusickThe word is replaced with alphabetically sorted file names that match the 49119464Smckusickpattern. If no file name is found that matches the pattern, 49219464Smckusickthe word is left unchanged. The character 49343084Scael.Ic \&. 49419464Smckusickat the start of a file name or immediately following a 49543084Scael.Ic \&/ , 49619463Smckusickand the character 49743084Scael.Ic \&/ , 49819463Smckusickmust be matched explicitly. 49943084Scael.Dp Ic \&*\& 50019463SmckusickMatches any string, including the null string. 50143084Scael.Dp Ic \&? 50219463SmckusickMatches any single character. 50343084Scael.Dp Ic \&[...] 50419464SmckusickMatches any one of the characters enclosed. 50519463SmckusickA pair of characters separated by 50643084Scael.Fl 50719464Smckusickmatches any character lexically between the pair. 50843084Scael.Dp 50943084Scael.Pp 51043084Scael.Ss Quoting . 51119463SmckusickThe following characters have a special meaning to the shell 51219463Smckusickand cause termination of a word unless quoted. 51343084Scael.Pp 51443084Scael.Df I 51543084Scael.Sy \&; \&& \&( \&) \&| \&< \&> 51643084Scael.Sy newline space tab 51743084Scael.De 51843084Scael.Pp 51919463SmckusickA character may be 52043084Scael.Ar quoted 52119464Smckusickby preceding it with a 52243084Scael.Sq Sy \e . 52343084Scael.Sy \enewline 52419463Smckusickis ignored. 52543084ScaelAll characters enclosed between a pair of quote marks 52643084Scael.Pq Sq , 52743084Scaelexcept a single quote, are quoted. Inside double quotes 52843084Scael.Pq Dq 52919463Smckusickparameter and command substitution occurs and 53043084Scael.Sy \e 53119463Smckusickquotes the characters 53243084Scael.Sy \e\' " 53319463Smckusickand 53443084Scael.Sy \&$ . 53543084Scael.Pp 53643084Scael.Dq \&$* 53719463Smckusickis equivalent to 53843084Scael.Dq Sy $1 $2 \&... 53919463Smckusickwhereas 54019463Smckusick.br 54143084Scael.Dq Sy $@ 54219463Smckusickis equivalent to 54343084Scael.Dq Sy $1 54443084Scael.Dq Sy $2 54543084Scael\&...\ . 54643084Scael.Pp 54743084Scael.Ss Prompting . 54819464SmckusickWhen used interactively, the shell prompts with the value of 54943084Scael.Ev PS1 55019463Smckusickbefore reading a command. 55119463SmckusickIf at any time a newline is typed and further input is needed 55219464Smckusickto complete a command, the secondary prompt 55343084Scael.Cx Sy $ 55443084Scael.Ev PS2 55543084Scael.Cx 55619463Smckusickis issued. 55743084Scael.Pp 55843084Scael.Ss Input/Output . 55919463SmckusickBefore a command is executed its input and output 56019463Smckusickmay be redirected using a special notation interpreted by the shell. 56119463SmckusickThe following may appear anywhere in a simple-command 56219463Smckusickor may precede or follow a 56343084Scael.Ar command 56419463Smckusickand are not passed on to the invoked command. 56519463SmckusickSubstitution occurs before 56643084Scael.Ar word 56719463Smckusickor 56843084Scael.Ar digit 56919463Smckusickis used. 57043084Scael.Tw Ic 57143084Scael.Tp Cx Ic \&< 57243084Scael.Cx \&\ \& 57343084Scael.Ar word 57443084Scael.Cx 57519463SmckusickUse file 57643084Scael.Ar word 57719463Smckusickas standard input (file descriptor 0). 57843084Scael.Tp Cx Ic \&> 57943084Scael.Cx \&\ \& 58043084Scael.Ar word 58143084Scael.Cx 58219463SmckusickUse file 58343084Scael.Ar word 58419463Smckusickas standard output (file descriptor 1). 58519464SmckusickIf the file does not exist, it is created; 58619463Smckusickotherwise it is truncated to zero length. 58743084Scael.Tp Cx Ic \&>\&> 58843084Scael.Cx \&\ \& 58943084Scael.Ar word 59043084Scael.Cx 59119463SmckusickUse file 59243084Scael.Ar word 59319463Smckusickas standard output. 59419464SmckusickIf the file exists, output is appended (by seeking to the end); 59519463Smckusickotherwise the file is created. 59643084Scael.Tp Cx Ic \&<\&< 59743084Scael.Cx \&\ \& 59843084Scael.Ar word 59943084Scael.Cx 60019463SmckusickThe shell input is read up to a line the same as 60143084Scael.Ar word , 60219463Smckusickor end of file. 60319464SmckusickThe resulting document becomes the standard input. 60419463SmckusickIf any character of 60543084Scael.Ar word 60619464Smckusickis quoted, no interpretation is placed upon the characters of the document; 60719463Smckusickotherwise, parameter and command substitution occurs, 60843084Scael.Sy \enewline 60919464Smckusickis ignored, and 61043084Scael.Sy \e 61119463Smckusickis used to quote the characters 61243084Scael.Sy \&$ \&\' 61319463Smckusickand the first character of 61443084Scael.Ar word . 61543084Scael.Tp Cx Ic \&<\&& 61643084Scael.Cx \&\ \& 61743084Scael.Ar digit 61843084Scael.Cx 61919463SmckusickThe standard input is duplicated from file descriptor 62043084Scael.Ar digit ; 62119463Smckusicksee 62243084Scael.Xr dup 2 . 62343084ScaelSimilarly for the standard output using 62443084Scael.Ic \&> . 62543084Scael.Tp Ic \&<\&&\- 62619463SmckusickThe standard input is closed. 62743084ScaelSimilarly for the standard output using 62843084Scael.Ic \&> . 62943084Scael.Tp 63043084Scael.Pp 63119464SmckusickIf one of the above is preceded by a digit, the 63219464Smckusickfile descriptor created is that specified by the digit 63319464Smckusick(instead of the default 0 or 1). For example, 63443084Scael.Pp 63543084Scael.Dl \&... 2>&1 63643084Scael.Pp 63719463Smckusickcreates file descriptor 2 to be a duplicate 63819463Smckusickof file descriptor 1. 63943084Scael.Pp 64019463SmckusickIf a command is followed by 64143084Scael.Ic \&& 64219464Smckusickthen the default standard input for the command is the empty file 64343084Scael.Pq Pa dev/null . 64419463SmckusickOtherwise, the environment for the execution of a command contains the 64519463Smckusickfile descriptors of the invoking shell as modified by input 64619463Smckusickoutput specifications. 64743084Scael.Pp 64843084Scael.Ss Environment 64919464SmckusickThe environment is a list of name-value pairs that is passed to 65019464Smckusickan executed program in the same way as a normal argument list; see 65143084Scael.Xr execve 2 65219463Smckusickand 65343084Scael.Xr environ 7 . 65419463SmckusickThe shell interacts with the environment in several ways. 65519464SmckusickOn invocation, the shell scans the environment and creates a 65643084Scael.Ar parameter 65719464Smckusickfor each name found, giving it the corresponding value. 65819463SmckusickExecuted commands inherit the same environment. 65919463SmckusickIf the user modifies the values of these 66043084Scael.Ar parameters 66119464Smckusickor creates new ones, none of these affects the environment unless the 66243084Scael.Ic export 66319463Smckusickcommand is used to bind the shell's 66443084Scael.Ar parameter 66519463Smckusickto the environment. 66619463SmckusickThe environment seen by any executed command is thus composed 66719463Smckusickof any unmodified name-value pairs originally inherited by the shell, 66819464Smckusickplus any modifications or additions, all of which must be noted in 66943084Scael.Ic export 67019463Smckusickcommands. 67143084Scael.Pp 67219463SmckusickThe environment for any 67343084Scael.Ar simple-command 67419463Smckusickmay be augmented by prefixing it with one or more assignments to 67543084Scael.Ar parameters . 67619463SmckusickThus these two lines are equivalent 67743084Scael.Pp 67843084Scael.Dl TERM=450 cmd args 67943084Scael.Dl (export TERM; TERM=450; cmd args) 68043084Scael.Pp 68119463SmckusickIf the 68243084Scael.Fl k 68319463Smckusickflag is set, 68443084Scael.Ar all 68519463Smckusickkeyword arguments are placed in the environment, 68643084Scaeleven if they occur after the command name. 68719464SmckusickThe following prints 'a=b c' and 'c': 68843084Scael.Pp 68943084Scael.Ds I 69019463Smckusickecho a=b c 69119463Smckusickset \-k 69219463Smckusickecho a=b c 69343084Scael.De 69443084Scael.Pp 69543084Scael.Ss Signals . 69619463SmckusickThe INTERRUPT and QUIT signals for an invoked 69719463Smckusickcommand are ignored if the command is followed by 69843084Scael.Ic \&& ; 69919464Smckusickotherwise signals have the values inherited by the shell from its parent. 70019463Smckusick(But see also 70143084Scael.Ic trap . ) 70243084Scael.Pp 70343084Scael.Ss Execution . 70419464SmckusickEach time a command is executed the above substitutions are carried out. 70519464SmckusickExcept for the 'special commands' listed below a new process is created and 70619463Smckusickan attempt is made to execute the command via an 70743084Scael.Xr execve 2 . 70843084Scael.Pp 70919463SmckusickThe shell parameter 71043084Scael.Cx Ic \&$ 71143084Scael.Ev $PATH 71243084Scael.Cx 71319464Smckusickdefines the search path for the directory containing the command. 71419464SmckusickEach alternative directory name is separated by a colon 71543084Scael.Pq Sy \&: . 71619463SmckusickThe default path is 71743084Scael.Pa :/bin:/usr/bin . 71843084ScaelIf the command name contains a 71943084Scael.Sy / , 72043084Scaelthe search path is not used. 72119464SmckusickOtherwise, each directory in the path is searched for an executable file. 72219463SmckusickIf the file has execute permission but is not an 72343084Scael.Pa a.out 72419464Smckusickfile, it is assumed to be a file containing shell commands. 72519463SmckusickA subshell (i.e., a separate process) is spawned to read it. 72619464SmckusickA parenthesized command is also executed in a subshell. 72743084Scael.Pp 72843084Scael.Ss Special commands . 72919463SmckusickThe following commands are executed in the shell process 73019463Smckusickand except where specified 73119463Smckusickno input output redirection is permitted for such commands. 73243084Scael.Tw Fl 73343084Scael.Tp Ic \&# 73427716SmckusickFor non-interactive shells, everything following the 73543084Scael.Ic \&# 73627716Smckusickis treated as a comment, i.e. the rest of the line is ignored. 73727716SmckusickFor interactive shells, the 73843084Scael.Ic \&# 73927716Smckusickhas no special effect. 74043084Scael.Tp Ic \&:\& 74119463SmckusickNo effect; the command does nothing. 74243084Scael.Tp Cx Ic \&.\& 74343084Scael.Ar file 74443084Scael.Cx 74519463SmckusickRead and execute commands from 74643084Scael.Ar file 74719464Smckusickand return. The search path 74843084Scael.Cx Ic \&$ 74943084Scael.Ev PATH 75043084Scael.Cx 75119463Smckusickis used to find the directory containing 75243084Scael.Ar file . 75343084Scael.Tp Cx Ic break 75443084Scael.Cx \&\ \& 75543084Scael.Op Ar n 75643084Scael.Cx 75719463SmckusickExit from the enclosing 75843084Scael.Ic for 75919463Smckusickor 76043084Scael.Ic while 76119463Smckusickloop, if any. 76219463SmckusickIf 76343084Scael.Ar n 76419464Smckusickis specified, break 76543084Scael.Ar n 76619463Smckusicklevels. 76743084Scael.Tp Cx Ic continue 76843084Scael.Cx \&\ \& 76943084Scael.Op Ar n 77043084Scael.Cx 77119463SmckusickResume the next iteration of the enclosing 77243084Scael.Ic for 77319463Smckusickor 77443084Scael.Ic while 77519464Smckusickloop. If 77643084Scael.Ar n 77719464Smckusickis specified, resume at the 77843084Scael.Cx Ar n 77943084Scael.Cx \'th 78043084Scael.Cx 78119463Smckusickenclosing loop. 78243084Scael.Tp Cx Ic cd 78343084Scael.Cx \&\ \& 78443084Scael.Op Ar arg 78543084Scael.Cx 78619463SmckusickChange the current directory to 78743084Scael.Ar arg . 78819464SmckusickThe shell parameter 78943084Scael.Cx Sy \&$ 79043084Scael.Ev $HOME 79143084Scael.Cx 79219463Smckusickis the default 79343084Scael.Ar arg . 79443084Scael.Tp Cx Ic eval 79543084Scael.Cx \&\ \& 79643084Scael.Op Ar arg \&... 79743084Scael.Cx 79819464SmckusickThe arguments are read as input to the shell 79919463Smckusickand the resulting command(s) executed. 80043084Scael.Tp Cx Ic exec 80143084Scael.Cx \&\ \& 80243084Scael.Op Ar arg \&... 80343084Scael.Cx 80419464SmckusickThe command specified by the arguments is executed in place of this shell 80519463Smckusickwithout creating a new process. 80619463SmckusickInput output arguments may appear and if no other 80719464Smckusickarguments are given cause the shell input output to be modified. 80843084Scael.Tp Cx Ic exit 80943084Scael.Cx \&\ \& 81043084Scael.Op Ar n 81143084Scael.Cx 81219464SmckusickCauses a non interactive shell to exit with the exit status specified by 81343084Scael.Ar n . 81419463SmckusickIf 81543084Scael.Ar n 81619464Smckusickis omitted, the exit status is that of the last command executed. 81719463Smckusick(An end of file will also exit from the shell.) 81843084Scael.Tp Cx Ic export 81943084Scael.Cx \&\ \& 82043084Scael.Op Ar name ... 82143084Scael.Cx 82219464SmckusickThe given names are marked for automatic export to the 82343084Scael.Ar environment 82419463Smckusickof subsequently-executed commands. 82519464SmckusickIf no arguments are given, a list of exportable names is printed. 82643084Scael.Tp Cx Ic login 82743084Scael.Cx \&\ \& 82843084Scael.Op Ar arg ... 82943084Scael.Cx 83019464SmckusickEquivalent to 'exec login arg ...'. 83143084Scael.Tp Cx Ic read 83243084Scael.Cx \&\ \& 83343084Scael.Ar name \&... 83443084Scael.Cx 83519463SmckusickOne line is read from the standard input; 83619464Smckusicksuccessive words of the input are assigned to the variables 83743084Scael.Ar name 83819464Smckusickin order, with leftover words to the last variable. 83919463SmckusickThe return code is 0 unless the end-of-file is encountered. 84043084Scael.Tp Cx Ic readonly 84143084Scael.Cx \&\ \& 84243084Scael.Op Ar name \&... 84343084Scael.Cx 84419463SmckusickThe given names are marked readonly and 84519463Smckusickthe values of the these names may not be changed 84619463Smckusickby subsequent assignment. 84719464SmckusickIf no arguments are given, a list of all readonly names is printed. 84843084Scael.Tp Cx Ic set 84943084Scael.Cx \&\ \& 85043084Scael.Op Fl eknptuvx 85143084Scael.Cx \&\ \& 85243084Scael.Op Ar arg ... 85343084Scael.Cx 85443084ScaelThe set flags are described in the options section at the beginning 85543084Scaelof this man page. 85619463SmckusickThe current set of flags may be found in 85743084Scael.Ic \&$\- . 85843084Scael.Pp 85943084ScaelRemaining arguments after the flag are positional 86019463Smckusickparameters and are assigned, in order, to 86143084Scael.Ic \&$1 , 86243084Scael.Ic \&$2 , 86319464Smckusicketc. If no arguments are given, the values of all names are printed. 86443084Scael.Tp Ic shift 86519463SmckusickThe positional parameters from 86643084Scael.Ic \&$2 ... 86719463Smckusickare renamed 86843084Scael.Ic $1 ... 86943084Scael.Tp Ic times 87019464SmckusickPrint the accumulated user and system times for processes run from the shell. 87143084Scael.Tp Cx Ic trap 87243084Scael.Cx \&\ \& 87343084Scael.Op Ar arg 87443084Scael.Cx \&\ \& 87543084Scael.Op Ar n 87643084Scael.Cx \&\ \& \&... 87743084Scael.Cx 87843084Scael.Ar Arg 87919464Smckusickis a command to be read and executed when the shell receives signal(s) 88043084Scael.Ar n . 88119463Smckusick(Note that 88243084Scael.Ar arg 88319464Smckusickis scanned once when the trap is set and once when the trap is taken.) 88419464SmckusickTrap commands are executed in order of signal number. If 88543084Scael.Ar arg 88619464Smckusickis absent, all trap(s) 88743084Scael.Ar n 88819464Smckusickare reset to their original values. 88919463SmckusickIf 89043084Scael.Ar arg 89119463Smckusickis the null 89219464Smckusickstring, this signal is ignored by the shell and by invoked commands. 89319463SmckusickIf 89443084Scael.Ar n 89519464Smckusickis 0, the command 89643084Scael.Ar arg 89719464Smckusickis executed on exit from the shell, otherwise upon receipt of signal 89843084Scael.Ar n 89919463Smckusickas numbered in 90043084Scael.Xr sigvec 2 . 90143084Scael.Ic Trap 90219464Smckusickwith no arguments prints a list of commands associated with each signal number. 90343084Scael.Tp Cx Ic umask 90443084Scael.Cx \&\ \& 90543084Scael.Op Ar nnn 90643084Scael.Cx 90719464SmckusickThe user file creation mask is set to the octal value 90843084Scael.Ar nnn 90919463Smckusick(see 91043084Scael.Xr umask 2 ) . 91119463SmckusickIf 91243084Scael.Ar nnn 91319463Smckusickis omitted, the current value of the mask is printed. 91443084Scael.Tp Cx Ic wait 91543084Scael.Cx \&\ \& 91643084Scael.Op Ar n 91743084Scael.Cx 91819464SmckusickWait for the specified process and report its termination status. If 91943084Scael.Ar n 92019464Smckusickis not given, all currently active child processes are waited for. 92119464SmckusickThe return code from this command is that of the process waited for. 92243084Scael.Tp 92343084Scael.Sh FILES 92443084Scael.Dw (longest file name here) 92543084Scael.Di L 92643084Scael.Dp Pa $HOME/.profile 92743084Scael.Dp Pa /tmp/sh* 92843084Scael.Dp Pa /dev/null 92943084Scael.Dp 93043084Scael.Sh SEE ALSO 93143084Scael.Xr csh 1 , 93243084Scael.Xr test 1 , 93343084Scael.Xr execve 2 , 93443084Scael.Xr environ 7 93543084Scael.Sh DIAGNOSTICS 93619464SmckusickErrors detected by the shell, such as syntax errors cause the shell 93719463Smckusickto return a non zero exit status. 93819463SmckusickIf the shell is being used non interactively 93919463Smckusickthen execution of the shell file is abandoned. 94019463SmckusickOtherwise, the shell returns the exit status of 94119463Smckusickthe last command executed (see also 94243084Scael.Ic exit ) . 94343084Scael.Sh HISTORY 94443084ScaelThe 94543084Scael.Nm Sh 94643084Scaelshell appeared in Version 6 AT&Y UNIX. 94719463Smckusick.SH BUGS 94843084ScaelIf 94943084Scael.Ic \&<\&< 95043084Scaelis used to provide standard input to an asynchronous 951*44957Scaelprocess invoked by 95243084Scael.Ic \&& , 95343084Scaelthe shell gets mixed up about naming the input document. 95443084ScaelA garbage file 95543084Scael.Pa /tmp/sh* 95643084Scaelis created, and the shell complains about 95719463Smckusicknot being able to find the file by another name. 95843084Scael.\" .Sh ENVIRONMENT 95943084Scael.\" /usr/src/bin/sh/defs.h:STRING *setenv(); 96043084Scael.\" /usr/src/bin/sh/name.c:STRING *setenv() 96143084Scael.\" /usr/src/bin/sh/service.c: xecenv=setenv(); 962