1*43084Scael.\" Copyright (c) 1990 The Regents of the University of California. 2*43084Scael.\" All rights reserved. 319463Smckusick.\" 4*43084Scael.\" %sccs.include.redist.man% 5*43084Scael.\" 6*43084Scael.\" @(#)sh.1 6.4 (Berkeley) 06/11/90 7*43084Scael.\" 8*43084Scael.Dd 9*43084Scael.Dt SH 1 10*43084Scael.Os ATT 7th 11*43084Scael.Sh NAME 12*43084Scael.Nm sh 13*43084Scael.Nd shell command interpreter 14*43084Scael.Sh SYNOPSIS 15*43084Scael.Nm sh 16*43084Scael.Op Fl ceiknrstuvx 17*43084Scael.Op arg 18*43084Scael.Ar ... 19*43084Scael.Sh DESCRIPTION 20*43084Scael.Nm Sh 2119464Smckusickis a command programming language that executes commands read from a terminal 22*43084Scaelor a file. The shell this page describes is called the 23*43084Scael.Em Bourne 24*43084Scaelshell. 25*43084Scael.Pp 26*43084ScaelCommand line options: 27*43084Scael.Pp 28*43084ScaelIf the first character of argument 0 if 29*43084Scael.Fl , 30*43084Scaelcommands are read from 31*43084Scael.Pa $HOME/.profile , 32*43084Scaelif such a file exists. 33*43084ScaelThe following flags are interpreted by the shell when it is invoked. 34*43084Scael.Tw Fl 35*43084Scael.Tp Cx Fl c 36*43084Scael.Cx \&\ \& 37*43084Scael.Ar string 38*43084Scael.Cx 39*43084ScaelCommands are read from 40*43084Scael.Ar string. 41*43084Scael.Tp Fl s 42*43084ScaelIf the 43*43084Scael.Fl s 44*43084Scaelflag is present or if no arguments remain 45*43084Scaelthen commands are read from the standard input. 46*43084ScaelShell output is written to file descriptor 2. 47*43084Scael.Tp Fl i 48*43084ScaelIf the 49*43084Scael.Fl i 50*43084Scaelflag is present or 51*43084Scaelif the shell input and output are attached to a terminal (as told by 52*43084Scael.Xr getty ) 53*43084Scaelthen this shell is 54*43084Scael.Em interactive . 55*43084ScaelIn this case the terminate signal SIGTERM (see 56*43084Scael.Xr sigvec 2 ) 57*43084Scaelis ignored (so that 'kill 0' 58*43084Scaeldoes not kill an interactive shell) and the interrupt signal 59*43084ScaelSIGINT is caught and ignored (so that 60*43084Scael.Xr wait 61*43084Scaelis interruptible). 62*43084ScaelIn all cases SIGQUIT is ignored by the shell. 63*43084Scael.Tp 64*43084Scael.Pp 65*43084ScaelThis next set of options can be used on the command line invoking 66*43084Scaelthe 67*43084Scael.Nm sh 68*43084Scaelor set with the interactive command 69*43084Scael.Ic set . 70*43084Scael.Tp Fl e 71*43084ScaelIf non interactive, exit immediately if a command fails. 72*43084Scael.Tp Fl k 73*43084ScaelAll keyword arguments are placed in the environment for a command, 74*43084Scaelnot just those that precede the command name. 75*43084Scael.Tp Fl n 76*43084ScaelRead commands but do not execute them. 77*43084Scael.Tp Fl t 78*43084ScaelExit after reading and executing one command. 79*43084Scael.Tp Fl u 80*43084ScaelTreat unset variables as an error when substituting. 81*43084Scael.Tp Fl v 82*43084ScaelPrint shell input lines as they are read. 83*43084Scael.Tp Fl x 84*43084ScaelPrint commands and their arguments as they are executed. 85*43084Scael.Tp Fl 86*43084ScaelTurn off the 87*43084Scael.Fl x 88*43084Scaeland 89*43084Scael.Fl v 90*43084Scaeloptions. 91*43084Scael.Tp 92*43084Scael.Ss Commands . 9319463SmckusickA 94*43084Scael.Em simple-command 9519463Smckusickis a sequence of non blank 96*43084Scael.Em words 9719463Smckusickseparated by blanks (a blank is a 98*43084Scael.Em tab 9919463Smckusickor a 100*43084Scael.Em space ) . 10119464SmckusickThe first word specifies the name of the command to be executed. 10219464SmckusickExcept as specified below the remaining words are passed as arguments 10319463Smckusickto the invoked command. 10419464SmckusickThe command name is passed as argument 0 (see 105*43084Scael.Xr execve 2 ) . 10619463SmckusickThe 107*43084Scael.Em value 10819463Smckusickof a simple-command is its exit status 109*43084Scaelif it terminates normally or 110*43084Scael.Cx Li 200+ 111*43084Scael.Em status 112*43084Scael.Cx 113*43084Scaelif it terminates abnormally (see 114*43084Scael.Ar sigvec 2 11519464Smckusickfor a list of status values). 116*43084Scael.Pp 11719463SmckusickA 118*43084Scael.Em pipeline 11919463Smckusickis a sequence of one or more 120*43084Scael.Em commands 12119463Smckusickseparated by 122*43084Scael.Sq Nm \&| . 12319464SmckusickThe standard output of each command but the last is connected by a 124*43084Scael.Xr pipe 2 12519463Smckusickto the standard input of the next command. 12619463SmckusickEach command is run as a separate process; 12719463Smckusickthe shell waits for the last command to terminate. 128*43084Scael.Pp 12919463SmckusickA 130*43084Scael.Em list 13119463Smckusickis a sequence of one or more 132*43084Scael.Em pipelines 13319463Smckusickseparated by 134*43084Scael.Nm \&; , 135*43084Scael.Nm \&& , 136*43084Scael.Nm \&&& 13719463Smckusickor 138*43084Scael.Nm \&| 139*43084Scaelor 140*43084Scael.Nm \&|\&| 14119463Smckusickand optionally terminated by 142*43084Scael.Nm \&; 14319463Smckusickor 144*43084Scael.Nm \&& . 145*43084Scael.Nm \&; 14619463Smckusickand 147*43084Scael.Nm \&& 14819464Smckusickhave equal precedence which is lower than that of 149*43084Scael.Nm \&&& 15019463Smckusickand 151*43084Scael.Nm \&|\&| , 152*43084Scael.Nm && 15319463Smckusickand 154*43084Scael.Nm \&|\&| , 15519463Smckusickalso have equal precedence. 15619464SmckusickA semicolon causes sequential execution; an ampersand causes the preceding 157*43084Scael.Em pipeline 15819464Smckusickto be executed without waiting for it to finish. The symbol 159*43084Scael.Nm \&&& 160*43084Scael.Pq Nm \&|\&| 16119463Smckusickcauses the 162*43084Scael.Em list 16319463Smckusickfollowing to be executed only if the preceding 164*43084Scael.Em pipeline 16519464Smckusickreturns a zero (non zero) value. Newlines may appear in a 166*43084Scael.Em list , 16719464Smckusickinstead of semicolons, to delimit commands. 168*43084Scael.Pp 16919463SmckusickA 170*43084Scael.Em command 17119464Smckusickis either a simple-command or one of the following. 17219463SmckusickThe value returned by a command is that of the 17319463Smckusicklast simple-command executed in the command. 174*43084Scael.Tw Fl 175*43084Scael.Tp Cx Ic for 176*43084Scael.Cx \&\ \& 177*43084Scael.Ar name 178*43084Scael.Cx \&\ \& 179*43084Scael.Op Ic in Ar word ... 180*43084Scael.Cx \&\ \& 181*43084Scael.Ic do 182*43084Scael.Cx \&\ \& 183*43084Scael.Ar list 184*43084Scael.Cx \&\ \& 185*43084Scael.Ic done 186*43084Scael.Cx 18719463SmckusickEach time a 188*43084Scael.Ic for 18919463Smckusickcommand is executed 190*43084Scael.Ar name 19119463Smckusickis set to the next word in the 192*43084Scael.Ic for 19327208Slepreauword list. 19419463SmckusickIf 195*43084Scael.Ic in 196*43084Scael.Ar word \&... 19719464Smckusickis omitted, 198*43084Scael.Ic in 199*43084Scael.Dq Ic \&$@ 20019464Smckusickis assumed. Execution ends when there are no more words in the list. 201*43084Scael.Tp Cx Ic case 202*43084Scael.Cx \&\ \& 203*43084Scael.Ar word 204*43084Scael.Cx \&\ \& 205*43084Scael.Ic in 206*43084Scael.Cx \&\ \&[ 207*43084Scael.Ar pattern 208*43084Scael.Cx \&\ \& 209*43084Scael.Op Ar \&| pattern ... 210*43084Scael.Cx \&\ \& 211*43084Scael.Ic \&) 212*43084Scael.Cx \&\ \& 213*43084Scael.Ar list 214*43084Scael.Cx \&\ \& 215*43084Scael.Ic \&;; 216*43084Scael.Cx \&]\ \& ... 217*43084Scael.Ar esac 218*43084Scael.Cx 21919463SmckusickA 220*43084Scael.Ic case 22119463Smckusickcommand executes the 222*43084Scael.Ar list 22319464Smckusickassociated with the first pattern that matches 224*43084Scael.Ar word . 22519464SmckusickThe form of the patterns is the same as that used for file name generation. 226*43084Scael.Tp Cx Ic if 227*43084Scael.Cx \&\ \& 228*43084Scael.Ar list 229*43084Scael.Cx \&\ \& 230*43084Scael.Ic then 231*43084Scael.Cx \&\ \& 232*43084Scael.Ar list 233*43084Scael.Cx \&\ \& 234*43084Scael.Op Ic elif Ar list Ic then Ar list 235*43084Scael.Cx \&\ \& 236*43084Scael.Cx \&... 237*43084Scael.Cx \&\ \& 238*43084Scael.Op Ic else Ar list 239*43084Scael.Cx \&\ \& 240*43084Scael.Ic fi 241*43084Scael.Cx 24219463SmckusickThe 243*43084Scael.Ar list 24419463Smckusickfollowing 245*43084Scael.Ic if 24619463Smckusickis executed and if it returns zero the 247*43084Scael.Ar list 24819463Smckusickfollowing 249*43084Scael.Ic then 25019464Smckusickis executed. Otherwise, the 251*43084Scael.Ar list 25219463Smckusickfollowing 253*43084Scael.Ic elif 25419464Smckusickis executed and if its value is zero the 255*43084Scael.Ar list 25619463Smckusickfollowing 257*43084Scael.Ic then 25819464Smckusickis executed. Failing that the 259*43084Scael.Ic else 260*43084Scael.Ar list 26119463Smckusickis executed. 262*43084Scael.Tp Cx Ic while 263*43084Scael.Cx \&\ \& 264*43084Scael.Ar list 265*43084Scael.Cx \&\ \& 266*43084Scael.Op Ic do Ar list 267*43084Scael.Cx \&\ \& 268*43084Scael.Ic done 269*43084Scael.Cx 27019463SmckusickA 271*43084Scael.Ic while 27219463Smckusickcommand repeatedly executes the 273*43084Scael.Ic while 274*43084Scael.Ar list 27519463Smckusickand if its value is zero executes the 276*43084Scael.Ic do 277*43084Scael.Ar list ; 27819464Smckusickotherwise the loop terminates. The value returned by a 279*43084Scael.Ic while 28019464Smckusickcommand is that of the last executed command in the 281*43084Scael.Ic do 282*43084Scael.Ar list . 283*43084Scael.Ic until 28419463Smckusickmay be used in place of 285*43084Scael.Ic while 28619464Smckusickto negate the loop termination test. 287*43084Scael.Tp Pq Ar list 28819463SmckusickExecute 289*43084Scael.Ar list 29019463Smckusickin a subshell. 291*43084Scael.Tp Cx \&{ 292*43084Scael.Ar list 293*43084Scael.Cx \&} 294*43084Scael.Cx 295*43084Scael.Ar list 29619463Smckusickis simply executed. 297*43084Scael.Tp 298*43084Scael.Pp 29919464SmckusickThe following words are only recognized as the first word of a command 30019463Smckusickand when not quoted. 301*43084Scael.Df I 302*43084Scael.Nm if then else elif fi case in esac 303*43084Scael.Nm for while until do done \&{ \&} 304*43084Scael.De 305*43084Scael.Pp 306*43084Scael.Ss Command substitution 307*43084ScaelThe standard output from a command enclosed in a pair of back quotes 308*43084Scael.Pq Ic \&`` 30919464Smckusickmay be used as part or all of a word; trailing newlines are removed. 310*43084Scael.Pp 311*43084Scael.Ss Parameter substitution . 31219463SmckusickThe character 313*43084Scael.Ic \&$ 31419464Smckusickis used to introduce substitutable parameters. 31519463SmckusickPositional parameters may be assigned values by 316*43084Scael.Ic set . 31719463SmckusickVariables may be set by writing 318*43084Scael.Pp 319*43084Scael.Df I 320*43084Scael.Ar name=value 321*43084Scael.Op Ar name=value 322*43084Scael\&... 323*43084Scael.De 324*43084Scael.Pp 325*43084Scael.Tp Cx Ic \&$ 326*43084Scael.Cx \&\ \& 327*43084Scael.Sy \&{ 328*43084Scael.Ar parameter 329*43084Scael.Sy \&} 330*43084Scael.Cx 33119463SmckusickA 332*43084Scael.Ar parameter 33319463Smckusickis a sequence of letters, digits or underscores (a 334*43084Scael.Ar name ) , 33519464Smckusicka digit, or any of the characters 336*43084Scael.Nm \&* \&@ \&# \&? \&\- \&$ \&!\ 33719463SmckusickThe value, if any, of the parameter is substituted. 33819463SmckusickThe braces are required only when 339*43084Scael.Ar parameter 34019463Smckusickis followed by a letter, digit, or underscore 34119464Smckusickthat is not to be interpreted as part of its name. If 342*43084Scael.Ar parameter 34319464Smckusickis a digit, it is a positional parameter. If 344*43084Scael.Ar parameter 34519463Smckusickis 346*43084Scael.Ic \&* 347*43084Scaelor 348*43084Scael.Ic \&@ 34919464Smckusickthen all the positional parameters, starting with 350*43084Scael.Ic $1 , 35119464Smckusickare substituted separated by spaces. 352*43084Scael.Ic $0 35319464Smckusickis set from argument zero when the shell is invoked. 354*43084Scael.Tp Cx Ic \&$ 355*43084Scael.Cx \&\ \& 356*43084Scael.Sy \&{ 357*43084Scael.Ar parameter 358*43084Scael.Fl 359*43084Scael.Ar word 360*43084Scael.Sy \&} 361*43084Scael.Cx 36219463SmckusickIf 363*43084Scael.Ar parameter 36419464Smckusickis set, substitute its value; otherwise substitute 365*43084Scael.Ar word . 366*43084Scael.Tp Cx Ic \&$ 367*43084Scael.Cx \&\ \& 368*43084Scael.Sy \&{ 369*43084Scael.Ar parameter 370*43084Scael.Ic \&= 371*43084Scael.Ar word 372*43084Scael.Cx \&\ \& 373*43084Scael.Sy \&} 374*43084Scael.Cx 37519463SmckusickIf 376*43084Scael.Ar parameter 37719464Smckusickis not set, set it to 378*43084Scael.Ar word ; 37919463Smckusickthe value of the parameter is then substituted. 38019464SmckusickPositional parameters may not be assigned to in this way. 381*43084Scael.Tp Cx Ic \&$ 382*43084Scael.Cx \&\ \& 383*43084Scael.Sy \&{ 384*43084Scael.Ar parameter 385*43084Scael.Ic \&? 386*43084Scael.Ar word 387*43084Scael.Sy \&} 388*43084Scael.Cx 38919463SmckusickIf 390*43084Scael.Ar parameter 39119464Smckusickis set, substitute its value; otherwise, print 392*43084Scael.Ar word 39319464Smckusickand exit from the shell. If 394*43084Scael.Ar word 39519464Smckusickis omitted, a standard message is printed. 396*43084Scael.Tp Cx Ic \&$ 397*43084Scael.Cx \&\ \& 398*43084Scael.Sy \&{ 399*43084Scael.Ar parameter 400*43084Scael.Ic \&+ 401*43084Scael.Ar word 402*43084Scael.Sy \&} 403*43084Scael.Cx 40419463SmckusickIf 405*43084Scael.Ar parameter 40619464Smckusickis set, substitute 407*43084Scael.Ar word ; 40819463Smckusickotherwise substitute nothing. 409*43084Scael.Tp 410*43084Scael.Pp 41119463SmckusickIn the above 412*43084Scael.Ar word 41319464Smckusickis not evaluated unless it is to be used as the substituted string. 41419464Smckusick(So that, for example, echo ${d\-\'pwd\'} will only execute 415*43084Scael.Ar pwd 41619463Smckusickif 417*43084Scael.Ar d 41819463Smckusickis unset.) 419*43084Scael.Pp 42019463SmckusickThe following 421*43084Scael.Ar parameters 42219463Smckusickare automatically set by the shell. 423*43084Scael.Pp 424*43084Scael.Dw Ds 425*43084Scael.Dp Ic \&# 42619463SmckusickThe number of positional parameters in decimal. 427*43084Scael.Dp Fl 42819463SmckusickOptions supplied to the shell on invocation or by 429*43084Scael.Ar set . 430*43084Scael.Dp Ic \&? 43119464SmckusickThe value returned by the last executed command in decimal. 432*43084Scael.Dp Ic \&$ 43319463SmckusickThe process number of this shell. 434*43084Scael.Dp Ic \&! 43519463SmckusickThe process number of the last background command invoked. 436*43084Scael.Dp 437*43084Scael.De 438*43084Scael.Pp 43919463SmckusickThe following 440*43084Scael.Ar parameters 44119463Smckusickare used but not set by the shell. 442*43084Scael.Pp 443*43084Scael.Ds I 444*43084Scael.Tp Ev HOME 44519463SmckusickThe default argument (home directory) for the 446*43084Scael.Ic cd 44719463Smckusickcommand. 448*43084Scael.Tp Ev PATH 44919463SmckusickThe search path for commands (see 450*43084Scael.Ar execution ) . 451*43084Scael.Tp Ev MAIL 45219463SmckusickIf this variable is set to the name of 45319464Smckusicka mail file, the shell informs the user of 45419463Smckusickthe arrival of mail in the specified file. 455*43084Scael.Tp Ev PS1 45619464SmckusickPrimary prompt string, by default '$ '. 457*43084Scael.Tp Ev PS2 45819464SmckusickSecondary prompt string, by default '> '. 459*43084Scael.Tp Ev IFS 46019464SmckusickInternal field separators, normally 461*43084Scael.Em space , 462*43084Scael.Em tab , 46319463Smckusickand 464*43084Scael.Em newline . 465*43084Scael.Ev IFS 466*43084Scaelis ignored if 467*43084Scael.Nm sh 46827716Smckusickis running as root or if the effective user id differs from the real user id. 469*43084Scael.Tp 470*43084Scael.De 471*43084Scael.Ss Blank interpretation . 47219463SmckusickAfter parameter and command substitution, 47319463Smckusickany results of substitution are scanned for internal field separator 47419463Smckusickcharacters (those found in 475*43084Scael.Cx Ic $ 476*43084Scael.Ev IFS ) 477*43084Scael.Cx 47819463Smckusickand split into distinct arguments where such characters are found. 47919463SmckusickExplicit null arguments ("" or \'\') are retained. 48019464SmckusickImplicit null arguments (those resulting from 481*43084Scael.Em parameters 48219463Smckusickthat have no values) are removed. 483*43084Scael.Pp 484*43084Scael.Ss File name generation . 48519464SmckusickFollowing substitution, each command word is scanned for the characters 486*43084Scael.Ic \&* , 487*43084Scael.Ic \&? 48819463Smckusickand 489*43084Scael.Ic \&[ . 49019464SmckusickIf one of these characters appears, the word is regarded as a pattern. 49119464SmckusickThe word is replaced with alphabetically sorted file names that match the 49219464Smckusickpattern. If no file name is found that matches the pattern, 49319464Smckusickthe word is left unchanged. The character 494*43084Scael.Ic \&. 49519464Smckusickat the start of a file name or immediately following a 496*43084Scael.Ic \&/ , 49719463Smckusickand the character 498*43084Scael.Ic \&/ , 49919463Smckusickmust be matched explicitly. 500*43084Scael.Dp Ic \&*\& 50119463SmckusickMatches any string, including the null string. 502*43084Scael.Dp Ic \&? 50319463SmckusickMatches any single character. 504*43084Scael.Dp Ic \&[...] 50519464SmckusickMatches any one of the characters enclosed. 50619463SmckusickA pair of characters separated by 507*43084Scael.Fl 50819464Smckusickmatches any character lexically between the pair. 509*43084Scael.Dp 510*43084Scael.Pp 511*43084Scael.Ss Quoting . 51219463SmckusickThe following characters have a special meaning to the shell 51319463Smckusickand cause termination of a word unless quoted. 514*43084Scael.Pp 515*43084Scael.Df I 516*43084Scael.Sy \&; \&& \&( \&) \&| \&< \&> 517*43084Scael.Sy newline space tab 518*43084Scael.De 519*43084Scael.Pp 52019463SmckusickA character may be 521*43084Scael.Ar quoted 52219464Smckusickby preceding it with a 523*43084Scael.Sq Sy \e . 524*43084Scael.Sy \enewline 52519463Smckusickis ignored. 526*43084ScaelAll characters enclosed between a pair of quote marks 527*43084Scael.Pq Sq , 528*43084Scaelexcept a single quote, are quoted. Inside double quotes 529*43084Scael.Pq Dq 53019463Smckusickparameter and command substitution occurs and 531*43084Scael.Sy \e 53219463Smckusickquotes the characters 533*43084Scael.Sy \e\' " 53419463Smckusickand 535*43084Scael.Sy \&$ . 536*43084Scael.Pp 537*43084Scael.Dq \&$* 53819463Smckusickis equivalent to 539*43084Scael.Dq Sy $1 $2 \&... 54019463Smckusickwhereas 54119463Smckusick.br 542*43084Scael.Dq Sy $@ 54319463Smckusickis equivalent to 544*43084Scael.Dq Sy $1 545*43084Scael.Dq Sy $2 546*43084Scael\&...\ . 547*43084Scael.Pp 548*43084Scael.Ss Prompting . 54919464SmckusickWhen used interactively, the shell prompts with the value of 550*43084Scael.Ev PS1 55119463Smckusickbefore reading a command. 55219463SmckusickIf at any time a newline is typed and further input is needed 55319464Smckusickto complete a command, the secondary prompt 554*43084Scael.Cx Sy $ 555*43084Scael.Ev PS2 556*43084Scael.Cx 55719463Smckusickis issued. 558*43084Scael.Pp 559*43084Scael.Ss Input/Output . 56019463SmckusickBefore a command is executed its input and output 56119463Smckusickmay be redirected using a special notation interpreted by the shell. 56219463SmckusickThe following may appear anywhere in a simple-command 56319463Smckusickor may precede or follow a 564*43084Scael.Ar command 56519463Smckusickand are not passed on to the invoked command. 56619463SmckusickSubstitution occurs before 567*43084Scael.Ar word 56819463Smckusickor 569*43084Scael.Ar digit 57019463Smckusickis used. 571*43084Scael.Tw Ic 572*43084Scael.Tp Cx Ic \&< 573*43084Scael.Cx \&\ \& 574*43084Scael.Ar word 575*43084Scael.Cx 57619463SmckusickUse file 577*43084Scael.Ar word 57819463Smckusickas standard input (file descriptor 0). 579*43084Scael.Tp Cx Ic \&> 580*43084Scael.Cx \&\ \& 581*43084Scael.Ar word 582*43084Scael.Cx 58319463SmckusickUse file 584*43084Scael.Ar word 58519463Smckusickas standard output (file descriptor 1). 58619464SmckusickIf the file does not exist, it is created; 58719463Smckusickotherwise it is truncated to zero length. 588*43084Scael.Tp Cx Ic \&>\&> 589*43084Scael.Cx \&\ \& 590*43084Scael.Ar word 591*43084Scael.Cx 59219463SmckusickUse file 593*43084Scael.Ar word 59419463Smckusickas standard output. 59519464SmckusickIf the file exists, output is appended (by seeking to the end); 59619463Smckusickotherwise the file is created. 597*43084Scael.Tp Cx Ic \&<\&< 598*43084Scael.Cx \&\ \& 599*43084Scael.Ar word 600*43084Scael.Cx 60119463SmckusickThe shell input is read up to a line the same as 602*43084Scael.Ar word , 60319463Smckusickor end of file. 60419464SmckusickThe resulting document becomes the standard input. 60519463SmckusickIf any character of 606*43084Scael.Ar word 60719464Smckusickis quoted, no interpretation is placed upon the characters of the document; 60819463Smckusickotherwise, parameter and command substitution occurs, 609*43084Scael.Sy \enewline 61019464Smckusickis ignored, and 611*43084Scael.Sy \e 61219463Smckusickis used to quote the characters 613*43084Scael.Sy \&$ \&\' 61419463Smckusickand the first character of 615*43084Scael.Ar word . 616*43084Scael.Tp Cx Ic \&<\&& 617*43084Scael.Cx \&\ \& 618*43084Scael.Ar digit 619*43084Scael.Cx 62019463SmckusickThe standard input is duplicated from file descriptor 621*43084Scael.Ar digit ; 62219463Smckusicksee 623*43084Scael.Xr dup 2 . 624*43084ScaelSimilarly for the standard output using 625*43084Scael.Ic \&> . 626*43084Scael.Tp Ic \&<\&&\- 62719463SmckusickThe standard input is closed. 628*43084ScaelSimilarly for the standard output using 629*43084Scael.Ic \&> . 630*43084Scael.Tp 631*43084Scael.Pp 63219464SmckusickIf one of the above is preceded by a digit, the 63319464Smckusickfile descriptor created is that specified by the digit 63419464Smckusick(instead of the default 0 or 1). For example, 635*43084Scael.Pp 636*43084Scael.Dl \&... 2>&1 637*43084Scael.Pp 63819463Smckusickcreates file descriptor 2 to be a duplicate 63919463Smckusickof file descriptor 1. 640*43084Scael.Pp 64119463SmckusickIf a command is followed by 642*43084Scael.Ic \&& 64319464Smckusickthen the default standard input for the command is the empty file 644*43084Scael.Pq Pa dev/null . 64519463SmckusickOtherwise, the environment for the execution of a command contains the 64619463Smckusickfile descriptors of the invoking shell as modified by input 64719463Smckusickoutput specifications. 648*43084Scael.Pp 649*43084Scael.Ss Environment 65019464SmckusickThe environment is a list of name-value pairs that is passed to 65119464Smckusickan executed program in the same way as a normal argument list; see 652*43084Scael.Xr execve 2 65319463Smckusickand 654*43084Scael.Xr environ 7 . 65519463SmckusickThe shell interacts with the environment in several ways. 65619464SmckusickOn invocation, the shell scans the environment and creates a 657*43084Scael.Ar parameter 65819464Smckusickfor each name found, giving it the corresponding value. 65919463SmckusickExecuted commands inherit the same environment. 66019463SmckusickIf the user modifies the values of these 661*43084Scael.Ar parameters 66219464Smckusickor creates new ones, none of these affects the environment unless the 663*43084Scael.Ic export 66419463Smckusickcommand is used to bind the shell's 665*43084Scael.Ar parameter 66619463Smckusickto the environment. 66719463SmckusickThe environment seen by any executed command is thus composed 66819463Smckusickof any unmodified name-value pairs originally inherited by the shell, 66919464Smckusickplus any modifications or additions, all of which must be noted in 670*43084Scael.Ic export 67119463Smckusickcommands. 672*43084Scael.Pp 67319463SmckusickThe environment for any 674*43084Scael.Ar simple-command 67519463Smckusickmay be augmented by prefixing it with one or more assignments to 676*43084Scael.Ar parameters . 67719463SmckusickThus these two lines are equivalent 678*43084Scael.Pp 679*43084Scael.Dl TERM=450 cmd args 680*43084Scael.Dl (export TERM; TERM=450; cmd args) 681*43084Scael.Pp 68219463SmckusickIf the 683*43084Scael.Fl k 68419463Smckusickflag is set, 685*43084Scael.Ar all 68619463Smckusickkeyword arguments are placed in the environment, 687*43084Scaeleven if they occur after the command name. 68819464SmckusickThe following prints 'a=b c' and 'c': 689*43084Scael.Pp 690*43084Scael.Ds I 69119463Smckusickecho a=b c 69219463Smckusickset \-k 69319463Smckusickecho a=b c 694*43084Scael.De 695*43084Scael.Pp 696*43084Scael.Ss Signals . 69719463SmckusickThe INTERRUPT and QUIT signals for an invoked 69819463Smckusickcommand are ignored if the command is followed by 699*43084Scael.Ic \&& ; 70019464Smckusickotherwise signals have the values inherited by the shell from its parent. 70119463Smckusick(But see also 702*43084Scael.Ic trap . ) 703*43084Scael.Pp 704*43084Scael.Ss Execution . 70519464SmckusickEach time a command is executed the above substitutions are carried out. 70619464SmckusickExcept for the 'special commands' listed below a new process is created and 70719463Smckusickan attempt is made to execute the command via an 708*43084Scael.Xr execve 2 . 709*43084Scael.Pp 71019463SmckusickThe shell parameter 711*43084Scael.Cx Ic \&$ 712*43084Scael.Ev $PATH 713*43084Scael.Cx 71419464Smckusickdefines the search path for the directory containing the command. 71519464SmckusickEach alternative directory name is separated by a colon 716*43084Scael.Pq Sy \&: . 71719463SmckusickThe default path is 718*43084Scael.Pa :/bin:/usr/bin . 719*43084ScaelIf the command name contains a 720*43084Scael.Sy / , 721*43084Scaelthe search path is not used. 72219464SmckusickOtherwise, each directory in the path is searched for an executable file. 72319463SmckusickIf the file has execute permission but is not an 724*43084Scael.Pa a.out 72519464Smckusickfile, it is assumed to be a file containing shell commands. 72619463SmckusickA subshell (i.e., a separate process) is spawned to read it. 72719464SmckusickA parenthesized command is also executed in a subshell. 728*43084Scael.Pp 729*43084Scael.Ss Special commands . 73019463SmckusickThe following commands are executed in the shell process 73119463Smckusickand except where specified 73219463Smckusickno input output redirection is permitted for such commands. 733*43084Scael.Tw Fl 734*43084Scael.Tp Ic \&# 73527716SmckusickFor non-interactive shells, everything following the 736*43084Scael.Ic \&# 73727716Smckusickis treated as a comment, i.e. the rest of the line is ignored. 73827716SmckusickFor interactive shells, the 739*43084Scael.Ic \&# 74027716Smckusickhas no special effect. 741*43084Scael.Tp Ic \&:\& 74219463SmckusickNo effect; the command does nothing. 743*43084Scael.Tp Cx Ic \&.\& 744*43084Scael.Ar file 745*43084Scael.Cx 74619463SmckusickRead and execute commands from 747*43084Scael.Ar file 74819464Smckusickand return. The search path 749*43084Scael.Cx Ic \&$ 750*43084Scael.Ev PATH 751*43084Scael.Cx 75219463Smckusickis used to find the directory containing 753*43084Scael.Ar file . 754*43084Scael.Tp Cx Ic break 755*43084Scael.Cx \&\ \& 756*43084Scael.Op Ar n 757*43084Scael.Cx 75819463SmckusickExit from the enclosing 759*43084Scael.Ic for 76019463Smckusickor 761*43084Scael.Ic while 76219463Smckusickloop, if any. 76319463SmckusickIf 764*43084Scael.Ar n 76519464Smckusickis specified, break 766*43084Scael.Ar n 76719463Smckusicklevels. 768*43084Scael.Tp Cx Ic continue 769*43084Scael.Cx \&\ \& 770*43084Scael.Op Ar n 771*43084Scael.Cx 77219463SmckusickResume the next iteration of the enclosing 773*43084Scael.Ic for 77419463Smckusickor 775*43084Scael.Ic while 77619464Smckusickloop. If 777*43084Scael.Ar n 77819464Smckusickis specified, resume at the 779*43084Scael.Cx Ar n 780*43084Scael.Cx \'th 781*43084Scael.Cx 78219463Smckusickenclosing loop. 783*43084Scael.Tp Cx Ic cd 784*43084Scael.Cx \&\ \& 785*43084Scael.Op Ar arg 786*43084Scael.Cx 78719463SmckusickChange the current directory to 788*43084Scael.Ar arg . 78919464SmckusickThe shell parameter 790*43084Scael.Cx Sy \&$ 791*43084Scael.Ev $HOME 792*43084Scael.Cx 79319463Smckusickis the default 794*43084Scael.Ar arg . 795*43084Scael.Tp Cx Ic eval 796*43084Scael.Cx \&\ \& 797*43084Scael.Op Ar arg \&... 798*43084Scael.Cx 79919464SmckusickThe arguments are read as input to the shell 80019463Smckusickand the resulting command(s) executed. 801*43084Scael.Tp Cx Ic exec 802*43084Scael.Cx \&\ \& 803*43084Scael.Op Ar arg \&... 804*43084Scael.Cx 80519464SmckusickThe command specified by the arguments is executed in place of this shell 80619463Smckusickwithout creating a new process. 80719463SmckusickInput output arguments may appear and if no other 80819464Smckusickarguments are given cause the shell input output to be modified. 809*43084Scael.Tp Cx Ic exit 810*43084Scael.Cx \&\ \& 811*43084Scael.Op Ar n 812*43084Scael.Cx 81319464SmckusickCauses a non interactive shell to exit with the exit status specified by 814*43084Scael.Ar n . 81519463SmckusickIf 816*43084Scael.Ar n 81719464Smckusickis omitted, the exit status is that of the last command executed. 81819463Smckusick(An end of file will also exit from the shell.) 819*43084Scael.Tp Cx Ic export 820*43084Scael.Cx \&\ \& 821*43084Scael.Op Ar name ... 822*43084Scael.Cx 82319464SmckusickThe given names are marked for automatic export to the 824*43084Scael.Ar environment 82519463Smckusickof subsequently-executed commands. 82619464SmckusickIf no arguments are given, a list of exportable names is printed. 827*43084Scael.Tp Cx Ic login 828*43084Scael.Cx \&\ \& 829*43084Scael.Op Ar arg ... 830*43084Scael.Cx 83119464SmckusickEquivalent to 'exec login arg ...'. 832*43084Scael.Tp Cx Ic read 833*43084Scael.Cx \&\ \& 834*43084Scael.Ar name \&... 835*43084Scael.Cx 83619463SmckusickOne line is read from the standard input; 83719464Smckusicksuccessive words of the input are assigned to the variables 838*43084Scael.Ar name 83919464Smckusickin order, with leftover words to the last variable. 84019463SmckusickThe return code is 0 unless the end-of-file is encountered. 841*43084Scael.Tp Cx Ic readonly 842*43084Scael.Cx \&\ \& 843*43084Scael.Op Ar name \&... 844*43084Scael.Cx 84519463SmckusickThe given names are marked readonly and 84619463Smckusickthe values of the these names may not be changed 84719463Smckusickby subsequent assignment. 84819464SmckusickIf no arguments are given, a list of all readonly names is printed. 849*43084Scael.Tp Cx Ic set 850*43084Scael.Cx \&\ \& 851*43084Scael.Op Fl eknptuvx 852*43084Scael.Cx \&\ \& 853*43084Scael.Op Ar arg ... 854*43084Scael.Cx 855*43084ScaelThe set flags are described in the options section at the beginning 856*43084Scaelof this man page. 85719463SmckusickThe current set of flags may be found in 858*43084Scael.Ic \&$\- . 859*43084Scael.Pp 860*43084ScaelRemaining arguments after the flag are positional 86119463Smckusickparameters and are assigned, in order, to 862*43084Scael.Ic \&$1 , 863*43084Scael.Ic \&$2 , 86419464Smckusicketc. If no arguments are given, the values of all names are printed. 865*43084Scael.Tp Ic shift 86619463SmckusickThe positional parameters from 867*43084Scael.Ic \&$2 ... 86819463Smckusickare renamed 869*43084Scael.Ic $1 ... 870*43084Scael.Tp Ic times 87119464SmckusickPrint the accumulated user and system times for processes run from the shell. 872*43084Scael.Tp Cx Ic trap 873*43084Scael.Cx \&\ \& 874*43084Scael.Op Ar arg 875*43084Scael.Cx \&\ \& 876*43084Scael.Op Ar n 877*43084Scael.Cx \&\ \& \&... 878*43084Scael.Cx 879*43084Scael.Ar Arg 88019464Smckusickis a command to be read and executed when the shell receives signal(s) 881*43084Scael.Ar n . 88219463Smckusick(Note that 883*43084Scael.Ar arg 88419464Smckusickis scanned once when the trap is set and once when the trap is taken.) 88519464SmckusickTrap commands are executed in order of signal number. If 886*43084Scael.Ar arg 88719464Smckusickis absent, all trap(s) 888*43084Scael.Ar n 88919464Smckusickare reset to their original values. 89019463SmckusickIf 891*43084Scael.Ar arg 89219463Smckusickis the null 89319464Smckusickstring, this signal is ignored by the shell and by invoked commands. 89419463SmckusickIf 895*43084Scael.Ar n 89619464Smckusickis 0, the command 897*43084Scael.Ar arg 89819464Smckusickis executed on exit from the shell, otherwise upon receipt of signal 899*43084Scael.Ar n 90019463Smckusickas numbered in 901*43084Scael.Xr sigvec 2 . 902*43084Scael.Ic Trap 90319464Smckusickwith no arguments prints a list of commands associated with each signal number. 904*43084Scael.Tp Cx Ic umask 905*43084Scael.Cx \&\ \& 906*43084Scael.Op Ar nnn 907*43084Scael.Cx 90819464SmckusickThe user file creation mask is set to the octal value 909*43084Scael.Ar nnn 91019463Smckusick(see 911*43084Scael.Xr umask 2 ) . 91219463SmckusickIf 913*43084Scael.Ar nnn 91419463Smckusickis omitted, the current value of the mask is printed. 915*43084Scael.Tp Cx Ic wait 916*43084Scael.Cx \&\ \& 917*43084Scael.Op Ar n 918*43084Scael.Cx 91919464SmckusickWait for the specified process and report its termination status. If 920*43084Scael.Ar n 92119464Smckusickis not given, all currently active child processes are waited for. 92219464SmckusickThe return code from this command is that of the process waited for. 923*43084Scael.Tp 924*43084Scael.Sh FILES 925*43084Scael.Dw (longest file name here) 926*43084Scael.Di L 927*43084Scael.Dp Pa $HOME/.profile 928*43084Scael.Dp Pa /tmp/sh* 929*43084Scael.Dp Pa /dev/null 930*43084Scael.Dp 931*43084Scael.Sh SEE ALSO 932*43084Scael.Xr csh 1 , 933*43084Scael.Xr test 1 , 934*43084Scael.Xr execve 2 , 935*43084Scael.Xr environ 7 936*43084Scael.Sh DIAGNOSTICS 93719464SmckusickErrors detected by the shell, such as syntax errors cause the shell 93819463Smckusickto return a non zero exit status. 93919463SmckusickIf the shell is being used non interactively 94019463Smckusickthen execution of the shell file is abandoned. 94119463SmckusickOtherwise, the shell returns the exit status of 94219463Smckusickthe last command executed (see also 943*43084Scael.Ic exit ) . 944*43084Scael.Sh HISTORY 945*43084ScaelThe 946*43084Scael.Nm Sh 947*43084Scaelshell appeared in Version 6 AT&Y UNIX. 94819463Smckusick.SH BUGS 949*43084ScaelIf 950*43084Scael.Ic \&<\&< 951*43084Scaelis used to provide standard input to an asynchronous 952*43084Scaelprocess invoked by 953*43084Scael.Ic \&& , 954*43084Scaelthe shell gets mixed up about naming the input document. 955*43084ScaelA garbage file 956*43084Scael.Pa /tmp/sh* 957*43084Scaelis created, and the shell complains about 95819463Smckusicknot being able to find the file by another name. 959*43084Scael.\" .Sh ENVIRONMENT 960*43084Scael.\" /usr/src/bin/sh/defs.h:STRING *setenv(); 961*43084Scael.\" /usr/src/bin/sh/name.c:STRING *setenv() 962*43084Scael.\" /usr/src/bin/sh/service.c: xecenv=setenv(); 963