37.\" 38.Dd May 5, 1995 39.Dt SH 1 40.Os 41.Sh NAME 42.Nm sh 43.Nd command interpreter (shell) 44.Sh SYNOPSIS 45.Nm 46.Op Fl /+abCEefIimnpsTuVvx 47.Op Fl /+o Ar longname 48.Op Fl c Ar string 49.Op Ar arg ... 50.Sh DESCRIPTION 51The 52.Nm 53utility is the standard command interpreter for the system. 54The current version of 55.Nm 56is in the process of being changed to 57conform with the 58.St -p1003.2 59specification for the shell. This version has many features which make 60it appear 61similar in some respects to the Korn shell, but it is not a Korn 62shell clone like 63.Xr pdksh 1 . 64Only features 65designated by POSIX, plus a few Berkeley extensions, are being 66incorporated into this shell. 67This man page is not intended to be a tutorial nor a complete 68specification of the shell. 69.Ss Overview 70The shell is a command that reads lines from 71either a file or the terminal, interprets them, and 72generally executes other commands. 73It is the program that is started when a user logs into the system, 74although a user can select a different shell with the 75.Xr chsh 1 76command. 77The shell 78implements a language that has flow control constructs, 79a macro facility that provides a variety of features in 80addition to data storage, along with builtin history and line 81editing capabilities. It incorporates many features to 82aid interactive use and has the advantage that the interpretative 83language is common to both interactive and non-interactive 84use (shell scripts). That is, commands can be typed directly 85to the running shell or can be put into a file, 86which can be executed directly by the shell. 87.Ss Invocation 88.\" 89.\" XXX This next sentence is incredibly confusing. 90.\" 91If no arguments are present and if the standard input of the shell 92is connected to a terminal 93(or if the 94.Fl i 95option is set), 96the shell is considered an interactive shell. An interactive shell 97generally prompts before each command and handles programming 98and command errors differently (as described below). 99When first starting, the shell inspects argument 0, and 100if it begins with a dash 101.Pq Li - , 102the shell is also considered a login shell. 103This is normally done automatically by the system 104when the user first logs in. A login shell first reads commands 105from the files 106.Pa /etc/profile 107and then 108.Pa .profile 109if they exist. If the environment variable 110.Ev ENV 111is set on entry to a shell, or is set in the 112.Pa .profile 113of a login shell, the shell then reads commands from the file named in 114.Ev ENV . 115Therefore, a user should place commands that are to be executed only 116at login time in the 117.Pa .profile 118file, and commands that are executed for every shell inside the 119.Ev ENV 120file. 121The user can set the 122.Ev ENV 123variable to some file by placing the following line in the file 124.Pa .profile 125in the home directory, 126substituting for 127.Pa .shinit 128the filename desired: 129.Pp 130.Dl ENV=$HOME/.shinit; export ENV 131.Pp 132The first non-option argument specified on the command line 133will be treated as the 134name of a file from which to read commands (a shell script), and 135the remaining arguments are set as the positional parameters 136of the shell ($1, $2, etc). Otherwise, the shell reads commands 137from its standard input. 138.Pp 139Unlike older versions of 140.Nm 141the 142.Ev ENV 143script is only sourced on invocation of interactive shells. This 144closes a well-known, and sometimes easily exploitable security 145hole related to poorly thought out 146.Ev ENV 147scripts. 148.Ss Argument List Processing 149All of the single letter options to 150.Nm 151have a corresponding long name, 152with the exception of 153.Fl c 154and 155.Fl /+o . 156These long names are provided next to the single letter options 157in the descriptions below. 158The long name for an option may be specified as an argument to the 159.Fl /+o 160option of 161.Xr sh 1 . 162Once the shell is running, 163the long name for an option may be specified as an argument to the 164.Fl /+o 165option of the 166.Ic set 167builtin command 168(described later in the section called 169.Sx Builtin Commands ) . 170Introducing an option with a dash 171.Pq Li - 172enables the option, 173while using a plus 174.Pq Li + 175disables the option. 176A 177.Dq Li -- 178or plain 179.Dq Li - 180will stop option processing and will force the remaining 181words on the command line to be treated as arguments. 182The 183.Fl /+o 184and 185.Fl c 186options do not have long names. 187They take arguments and are described after the single letter options. 188.Bl -tag -width indent 189.It Fl a Li allexport 190Flag variables for export when assignments are made to them. 191.It Fl b Li notify 192Enable asynchronous notification of background job 193completion. 194(UNIMPLEMENTED) 195.It Fl C Li noclobber 196Do not overwrite existing files with 197.Dq Li > . 198.It Fl E Li emacs 199Enable the builtin 200.Xr emacs 1 201command line editor (disables the 202.Fl V 203option if it has been set). 204.It Fl e Li errexit 205Exit immediately if any untested command fails in non-interactive mode. 206The exit status of a command is considered to be 207explicitly tested if the command is used to control 208an if, elif, while, or until; or if the command is the left 209hand operand of an 210.Dq Li && 211or 212.Dq Li || 213operator. 214.It Fl f Li noglob 215Disable pathname expansion. 216.It Fl I Li ignoreeof 217Ignore 218.Dv EOF Ns ' Ns s 219from input when in interactive mode. 220.It Fl i Li interactive 221Force the shell to behave interactively. 222.It Fl m Li monitor 223Turn on job control (set automatically when interactive). 224.It Fl n Li noexec 225If not interactive, read commands but do not 226execute them. This is useful for checking the 227syntax of shell scripts. 228.It Fl p Li privileged 229Turn on privileged mode. This mode is enabled on startup 230if either the effective user or group id is not equal to the 231real user or group id. Turning this mode off sets the 232effective user and group ids to the real user and group ids. 233When this mode is enabled for interactive shells, the file 234.Pa /etc/suid_profile 235is sourced instead of 236.Pa ~/.profile 237after 238.Pa /etc/profile 239is sourced, and the contents of the 240.Ev ENV 241variable are ignored. 242.It Fl s Li stdin 243Read commands from standard input (set automatically 244if no file arguments are present). This option has 245no effect when set after the shell has already started 246running (i.e. when set with the 247.Ic set 248command). 249.It Fl T Li asynctraps 250When waiting for a child, execute traps immediately. 251If this option is not set, 252traps are executed after the child exits, 253as specified in 254.St -p1003.2 255This nonstandard option is useful for putting guarding shells around 256children that block signals. The surrounding shell may kill the child 257or it may just return control to the tty and leave the child alone, 258like this: 259.Bd -literal -offset indent 260sh -T -c "trap 'exit 1' 2 ; some-blocking-program" 261.Ed 262.Pp 263.It Fl u Li nounset 264Write a message to standard error when attempting 265to expand a variable that is not set, and if the 266shell is not interactive, exit immediately. 267.It Fl V Li vi 268Enable the builtin 269.Xr vi 1 270command line editor (disables 271.Fl E 272if it has been set). 273.It Fl v Li verbose 274The shell writes its input to standard error 275as it is read. Useful for debugging. 276.It Fl x Li xtrace 277Write each command 278(preceded by 279.Dq Li +\ ) 280to standard error before it is executed. 281Useful for debugging. 282.El 283.Pp 284The 285.Fl c 286option may be used to pass its string argument to the shell 287to be interpreted as input. 288Keep in mind that this option only accepts a single string as its 289argument, hence multi-word strings must be quoted. 290.Pp 291The 292.Fl /+o 293option takes as its only argument the long name of an option 294to be enabled or disabled. 295For example, the following two invocations of 296.Nm 297both enable the builtin 298.Xr emacs 1 299command line editor: 300.Bd -literal -offset indent 301set -E 302set -o emacs 303.Ed 304.Pp 305If used without an argument, the 306.Fl o 307option displays the current option settings in a human-readable format. 308If 309.Cm +o 310is used without an argument, the current option settings are output 311in a format suitable for re-input into the shell. 312.Ss Lexical Structure 313The shell reads input in terms of lines from a file and breaks 314it up into words at whitespace (blanks and tabs), and at 315certain sequences of 316characters called 317.Dq operators , 318which are special to the shell. 319There are two types of operators: control operators and 320redirection operators (their meaning is discussed later). 321The following is a list of valid operators: 322.Bl -tag -width indent 323.It Control operators: 324.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 325.It Li & Ta Li && Ta Li ( Ta Li ) Ta Li \en 326.It Li ;; Ta Li ; Ta Li | Ta Li || 327.El 328.It Redirection operators: 329.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 330.It Li < Ta Li > Ta Li << Ta Li >> Ta Li <> 331.It Li <& Ta Li >& Ta Li <<- Ta Li >| 332.El 333.El 334.Ss Quoting 335Quoting is used to remove the special meaning of certain characters 336or words to the shell, such as operators, whitespace, or 337keywords. There are three types of quoting: matched single quotes, 338matched double quotes, and backslash. 339.Bl -tag -width indent 340.It Single Quotes 341Enclosing characters in single quotes preserves the literal 342meaning of all the characters (except single quotes, making 343it impossible to put single-quotes in a single-quoted string). 344.It Double Quotes 345Enclosing characters within double quotes preserves the literal 346meaning of all characters except dollarsign 347.Pq Li $ , 348backquote 349.Pq Li ` , 350and backslash 351.Pq Li \e . 352The backslash inside double quotes is historically weird. 353It remains literal unless it precedes the following characters, 354which it serves to quote: 355.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 356.It Li $ Ta Li ` Ta Li \&" Ta Li \e\ Ta Li \en 357.El 358.It Backslash 359A backslash preserves the literal meaning of the following 360character, with the exception of the newline character 361.Pq Li \en . 362A backslash preceding a newline is treated as a line continuation. 363.El 364.Ss Reserved Words 365Reserved words are words that have special meaning to the 366shell and are recognized at the beginning of a line and 367after a control operator. The following are reserved words: 368.Bl -column "doneXX" "elifXX" "elseXX" "untilXX" "whileX" -offset center 369.It Li \&! Ta { Ta } Ta Ic case Ta Ic do 370.It Ic done Ta Ic elif Ta Ic else Ta Ic esac Ta Ic fi 371.It Ic for Ta Ic if Ta Ic then Ta Ic until Ta Ic while 372.El 373.Ss Aliases 374An alias is a name and corresponding value set using the 375.Ic alias 376builtin command. Whenever a reserved word may occur (see above), 377and after checking for reserved words, the shell 378checks the word to see if it matches an alias. 379If it does, it replaces it in the input stream with its value. 380For example, if there is an alias called 381.Dq Li lf 382with the value 383.Dq Li ls -F , 384then the input 385.Bd -literal -offset indent 386lf foobar 387.Ed 388.Pp 389would become 390.Bd -literal -offset indent 391ls -F foobar 392.Ed 393.Pp 394Aliases provide a convenient way for naive users to 395create shorthands for commands without having to learn how 396to create functions with arguments. They can also be 397used to create lexically obscure code. This use is discouraged. 398.Ss Commands 399The shell interprets the words it reads according to a 400language, the specification of which is outside the scope 401of this man page (refer to the BNF in the 402.St -p1003.2 403document). Essentially though, a line is read and if 404the first word of the line (or after a control operator) 405is not a reserved word, then the shell has recognized a 406simple command. Otherwise, a complex command or some 407other special construct may have been recognized. 408.Ss Simple Commands 409If a simple command has been recognized, the shell performs 410the following actions: 411.Bl -enum 412.It 413Leading words of the form 414.Dq Li name=value 415are stripped off and assigned to the environment of 416the simple command. Redirection operators and 417their arguments (as described below) are stripped 418off and saved for processing. 419.It 420The remaining words are expanded as described in 421the section called 422.Sx Word Expansions , 423and the first remaining word is considered the command 424name and the command is located. The remaining 425words are considered the arguments of the command. 426If no command name resulted, then the 427.Dq Li name=value 428variable assignments recognized in 1) affect the 429current shell. 430.It 431Redirections are performed as described in 432the next section. 433.El 434.Ss Redirections 435Redirections are used to change where a command reads its input 436or sends its output. In general, redirections open, close, or 437duplicate an existing reference to a file. The overall format 438used for redirection is: 439.Pp 440.Dl [n] redir-op file 441.Pp 442The 443.Ql redir-op 444is one of the redirection operators mentioned 445previously. The following gives some examples of how these 446operators can be used. 447Note that stdin and stdout are commonly used abbreviations 448for standard input and standard output respectively. 449.Bl -tag -width "1234567890XX" -offset indent 450.It Li [n]> file 451redirect stdout (or file descriptor n) to file 452.It Li [n]>| file 453same as above, but override the 454.Fl C 455option 456.It Li [n]>> file 457append stdout (or file descriptor n) to file 458.It Li [n]< file 459redirect stdin (or file descriptor n) from file 460.It Li [n]<> file 461redirect stdin (or file descriptor n) to and from file 462.It Li [n1]<&n2 463duplicate stdin (or file descriptor n1) from file descriptor n2 464.It Li [n]<&- 465close stdin (or file descriptor n) 466.It Li [n1]>&n2 467duplicate stdout (or file descriptor n1) to file descriptor n2 468.It Li [n]>&- 469close stdout (or file descriptor n) 470.El 471.Pp 472The following redirection is often called a 473.Dq here-document . 474.Bd -literal -offset indent 475[n]<< delimiter 476 here-doc-text 477 ... 478delimiter 479.Ed 480.Pp 481All the text on successive lines up to the delimiter is 482saved away and made available to the command on standard 483input, or file descriptor n if it is specified. If the delimiter 484as specified on the initial line is quoted, then the here-doc-text 485is treated literally, otherwise the text is subjected to 486parameter expansion, command substitution, and arithmetic 487expansion (as described in the section on 488.Sx Word Expansions ) . 489If the operator is 490.Dq Li <<- 491instead of 492.Dq Li << , 493then leading tabs 494in the here-doc-text are stripped. 495.Ss Search and Execution 496There are three types of commands: shell functions, 497builtin commands, and normal programs. 498The command is searched for (by name) in that order. 499The three types of commands are all executed in a different way. 500.Pp 501When a shell function is executed, all of the shell positional 502parameters (except $0, which remains unchanged) are 503set to the arguments of the shell function. 504The variables which are explicitly placed in the environment of 505the command (by placing assignments to them before the 506function name) are made local to the function and are set 507to the values given. 508Then the command given in the function definition is executed. 509The positional parameters are restored to their original values 510when the command completes. 511This all occurs within the current shell. 512.Pp 513Shell builtin commands are executed internally to the shell, without 514spawning a new process. 515.Pp 516Otherwise, if the command name does not match a function 517or builtin command, the command is searched for as a normal 518program in the filesystem (as described in the next section). 519When a normal program is executed, the shell runs the program, 520passing the arguments and the environment to the program. 521If the program is not a normal executable file 522(i.e. if it does not begin with the 523.Qq magic number 524whose 525.Tn ASCII 526representation is 527.Qq #! , 528resulting in an 529.Er ENOEXEC 530return value from 531.Xr execve 2 ) 532the shell will interpret the program in a subshell. 533The child shell will reinitialize itself in this case, 534so that the effect will be 535as if a new shell had been invoked to handle the ad-hoc shell script, 536except that the location of hashed commands located in 537the parent shell will be remembered by the child. 538.Pp 539Note that previous versions of this document 540and the source code itself misleadingly and sporadically 541refer to a shell script without a magic number 542as a 543.Qq shell procedure . 544.Ss Path Search 545When locating a command, the shell first looks to see if 546it has a shell function by that name. Then it looks for a 547builtin command by that name. If a builtin command is not found, 548one of two things happen: 549.Bl -enum 550.It 551Command names containing a slash are simply executed without 552performing any searches. 553.It 554The shell searches each entry in 555.Ev PATH 556in turn for the command. The value of the 557.Ev PATH 558variable should be a series of 559entries separated by colons. Each entry consists of a 560directory name. 561The current directory 562may be indicated implicitly by an empty directory name, 563or explicitly by a single period. 564.El 565.Ss Command Exit Status 566Each command has an exit status that can influence the behavior 567of other shell commands. The paradigm is that a command exits 568with zero for normal or success, and non-zero for failure, 569error, or a false indication. The man page for each command 570should indicate the various exit codes and what they mean. 571Additionally, the builtin commands return exit codes, as does 572an executed shell function. 573.Pp 574If a command is terminated by a signal, its exit status is 128 plus 575the signal number. Signal numbers are defined in the header file 576.Aq Pa sys/signal.h . 577.Ss Complex Commands 578Complex commands are combinations of simple commands 579with control operators or reserved words, together creating a larger complex 580command. More generally, a command is one of the following: 581.Bl -item -offset indent 582.It 583simple command 584.It 585pipeline 586.It 587list or compound-list 588.It 589compound command 590.It 591function definition 592.El 593.Pp 594Unless otherwise stated, the exit status of a command is 595that of the last simple command executed by the command. 596.Ss Pipelines 597A pipeline is a sequence of one or more commands separated 598by the control operator |. The standard output of all but 599the last command is connected to the standard input 600of the next command. The standard output of the last 601command is inherited from the shell, as usual. 602.Pp 603The format for a pipeline is: 604.Pp 605.Dl [!] command1 [ | command2 ...] 606.Pp 607The standard output of command1 is connected to the standard 608input of command2. The standard input, standard output, or 609both of a command is considered to be assigned by the 610pipeline before any redirection specified by redirection 611operators that are part of the command. 612.Pp 613If the pipeline is not in the background (discussed later), 614the shell waits for all commands to complete. 615.Pp 616If the reserved word ! does not precede the pipeline, the 617exit status is the exit status of the last command specified 618in the pipeline. Otherwise, the exit status is the logical 619NOT of the exit status of the last command. That is, if 620the last command returns zero, the exit status is 1; if 621the last command returns greater than zero, the exit status 622is zero. 623.Pp 624Because pipeline assignment of standard input or standard 625output or both takes place before redirection, it can be 626modified by redirection. For example: 627.Pp 628.Dl $ command1 2>&1 | command2 629.Pp 630sends both the standard output and standard error of 631.Ql command1 632to the standard input of 633.Ql command2 . 634.Pp 635A 636.Dq Li \&; 637or newline terminator causes the preceding 638AND-OR-list 639(described below in the section called 640.Sx Short-Circuit List Operators ) 641to be executed sequentially; 642an 643.Dq Li & 644causes asynchronous execution of the preceding AND-OR-list. 645.Pp 646Note that unlike some other shells, 647.Nm 648executes each process in the pipeline as a child of the 649.Nm 650process. 651Shell builtin commands are the exception to this rule. 652They are executed in the current shell, although they do not affect its 653environment when used in pipelines. 654.Ss Background Commands (&) 655If a command is terminated by the control operator ampersand 656.Pq Li & , 657the shell executes the command asynchronously; 658the shell does not wait for the command to finish 659before executing the next command. 660.Pp 661The format for running a command in background is: 662.Bd -literal -offset indent 663command1 & [command2 & ...] 664.Ed 665.Pp 666If the shell is not interactive, the standard input of an 667asynchronous command is set to /dev/null. 668.Ss Lists (Generally Speaking) 669A list is a sequence of zero or more commands separated by 670newlines, semicolons, or ampersands, 671and optionally terminated by one of these three characters. 672The commands in a 673list are executed in the order they are written. 674If command is followed by an ampersand, the shell starts the 675command and immediately proceed onto the next command; 676otherwise it waits for the command to terminate before 677proceeding to the next one. 678.Ss Short-Circuit List Operators 679.Dq Li && 680and 681.Dq Li || 682are AND-OR list operators. 683.Dq Li && 684executes the first command, and then executes the second command 685if the exit status of the first command is zero. 686.Dq Li || 687is similar, but executes the second command if the exit 688status of the first command is nonzero. 689.Dq Li && 690and 691.Dq Li || 692both have the same priority. 693.Ss Flow-Control Constructs (if, while, for, case) 694The syntax of the 695.Ic if 696command is: 697.\" 698.\" XXX Use .Dl to work around broken handling of .Ic inside .Bd and .Ed . 699.\" 700.Dl Ic if Ar list 701.Dl Ic then Ar list 702.Dl [ Ic elif Ar list 703.Dl Ic then Ar list ] ... 704.Dl [ Ic else Ar list ] 705.Dl Ic fi 706.Pp 707The syntax of the 708.Ic while 709command is: 710.Dl Ic while Ar list 711.Dl Ic do Ar list 712.Dl Ic done 713.Pp 714The two lists are executed repeatedly while the exit status of the 715first list is zero. 716The 717.Ic until 718command is similar, but has the word 719.Ic until 720in place of 721.Ic while , 722which causes it to 723repeat until the exit status of the first list is zero. 724.Pp 725The syntax of the 726.Ic for 727command is: 728.Dl Ic for Ar variable Ic in Ar word ... 729.Dl Ic do Ar list 730.Dl Ic done 731.Pp 732The words are expanded, and then the list is executed 733repeatedly with the variable set to each word in turn. 734The 735.Ic do 736and 737.Ic done 738commands may be replaced with 739.Dq Li { 740and 741.Dq Li } . 742.Pp 743The syntax of the 744.Ic break 745and 746.Ic continue 747commands is: 748.Dl Ic break Op Ar num 749.Dl Ic continue Op Ar num 750.Pp 751The 752.Ic break 753command terminates the 754.Ar num 755innermost 756.Ic for 757or 758.Ic while 759loops. 760The 761.Ic continue 762command continues with the next iteration of the innermost loop. 763These are implemented as builtin commands. 764.Pp 765The syntax of the 766.Ic case 767command is 768.Dl Ic case Ar word Ic in 769.Dl pattern) list ;; 770.Dl ... 771.Dl Ic esac 772.Pp 773The pattern can actually be one or more patterns 774(see 775.Sx Shell Patterns 776described later), 777separated by 778.Dq Li \&| 779characters. 780.Ss Grouping Commands Together 781Commands may be grouped by writing either 782.Bd -literal -offset indent 783(list) 784.Ed 785.Pp 786or 787.Bd -literal -offset indent 788{ list; } 789.Ed 790.Pp 791The first form executes the commands in a subshell. 792Note that builtin commands thus executed do not affect the current shell. 793The second form does not fork another shell, 794so it is slightly more efficient. 795Grouping commands together this way allows the user to 796redirect their output as though they were one program: 797.Bd -literal -offset indent 798{ echo -n "hello"; echo " world"; } > greeting 799.Ed 800.Ss Functions 801The syntax of a function definition is 802.Bd -literal -offset indent 803name ( ) command 804.Ed 805.Pp 806A function definition is an executable statement; when 807executed it installs a function named name and returns an 808exit status of zero. The command is normally a list 809enclosed between 810.Dq Li { 811and 812.Dq Li } . 813.Pp 814Variables may be declared to be local to a function by 815using the 816.Ic local 817command. 818This should appear as the first statement of a function, 819and the syntax is: 820.Bd -ragged -offset indent 821.Ic local 822.Op Ar variable ... 823.Op Ar - 824.Ed 825.Pp 826The 827.Ic local 828command is implemented as a builtin command. 829.Pp 830When a variable is made local, it inherits the initial 831value and exported and readonly flags from the variable 832with the same name in the surrounding scope, if there is 833one. Otherwise, the variable is initially unset. The shell 834uses dynamic scoping, so that if the variable 835.Em x 836is made local to function 837.Em f , 838which then calls function 839.Em g , 840references to the variable 841.Em x 842made inside 843.Em g 844will refer to the variable 845.Em x 846declared inside 847.Em f , 848not to the global variable named 849.Em x . 850.Pp 851The only special parameter than can be made local is 852.Dq Li - . 853Making 854.Dq Li - 855local causes any shell options that are 856changed via the set command inside the function to be 857restored to their original values when the function 858returns. 859.Pp 860The syntax of the 861.Ic return 862command is 863.Bd -ragged -offset indent 864.Ic return 865.Op Ar exitstatus 866.Ed 867.Pp 868It terminates the currently executing function. 869The 870.Ic return 871command is implemented as a builtin command. 872.Ss Variables and Parameters 873The shell maintains a set of parameters. A parameter 874denoted by a name is called a variable. When starting up, 875the shell turns all the environment variables into shell 876variables. New variables can be set using the form 877.Bd -literal -offset indent 878name=value 879.Ed 880.Pp 881Variables set by the user must have a name consisting solely 882of alphabetics, numerics, and underscores. 883The first letter of a variable name must not be numeric. 884A parameter can also be denoted by a number 885or a special character as explained below. 886.Ss Positional Parameters 887A positional parameter is a parameter denoted by a number greater than zero. 888The shell sets these initially to the values of its command line 889arguments that follow the name of the shell script. The 890.Ic set 891builtin command can also be used to set or reset them. 892.Ss Special Parameters 893A special parameter is a parameter denoted by one of the following 894special characters. The value of the parameter is listed 895next to its character. 896.Bl -hang 897.It Li * 898Expands to the positional parameters, starting from one. When 899the expansion occurs within a double-quoted string 900it expands to a single field with the value of each parameter 901separated by the first character of the 902.Ev IFS 903variable, 904or by a 905.Aq space 906if 907.Ev IFS 908is unset. 909.It Li @ 910Expands to the positional parameters, starting from one. When 911the expansion occurs within double-quotes, each positional 912parameter expands as a separate argument. 913If there are no positional parameters, the 914expansion of 915.Li @ 916generates zero arguments, even when 917.Li @ 918is double-quoted. What this basically means, for example, is 919if $1 is 920.Dq abc 921and $2 is 922.Dq def ghi , 923then 924.Qq Li $@ 925expands to 926the two arguments: 927.Bd -literal -offset indent 928"abc" "def ghi" 929.Ed 930.It Li # 931Expands to the number of positional parameters. 932.It Li \&? 933Expands to the exit status of the most recent pipeline. 934.It Li - 935(hyphen) Expands to the current option flags (the single-letter 936option names concatenated into a string) as specified on 937invocation, by the set builtin command, or implicitly 938by the shell. 939.It Li $ 940Expands to the process ID of the invoked shell. A subshell 941retains the same value of $ as its parent. 942.It Li \&! 943Expands to the process ID of the most recent background 944command executed from the current shell. For a 945pipeline, the process ID is that of the last command in the 946pipeline. 947.It Li 0 948(zero) Expands to the name of the shell or shell script. 949.El 950.Ss Word Expansions 951This clause describes the various expansions that are 952performed on words. Not all expansions are performed on 953every word, as explained later. 954.Pp 955Tilde expansions, parameter expansions, command substitutions, 956arithmetic expansions, and quote removals that occur within 957a single word expand to a single field. It is only field 958splitting or pathname expansion that can create multiple 959fields from a single word. 960The single exception to this rule is 961the expansion of the special parameter 962.Li @ 963within double-quotes, 964as was described above. 965.Pp 966The order of word expansion is: 967.Bl -enum 968.It 969Tilde Expansion, Parameter Expansion, Command Substitution, 970Arithmetic Expansion (these all occur at the same time). 971.It 972Field Splitting is performed on fields generated by step (1) 973unless the 974.Ev IFS 975variable is null. 976.It 977Pathname Expansion (unless the 978.Fl f 979option is in effect). 980.It 981Quote Removal. 982.El 983.Pp 984The 985.Dq Li $ 986character is used to introduce parameter expansion, command 987substitution, or arithmetic evaluation. 988.Ss Tilde Expansion (substituting a user's home directory) 989A word beginning with an unquoted tilde character 990.Pq Li ~ 991is 992subjected to tilde expansion. 993All the characters up to a slash 994.Pq Li / 995or the end of the word are treated as a username 996and are replaced with the user's home directory. If the 997username is missing (as in ~/foobar), the tilde is replaced 998with the value of the HOME variable (the current user's 999home directory). 1000.Ss Parameter Expansion 1001The format for parameter expansion is as follows: 1002.Bd -literal -offset indent 1003${expression} 1004.Ed 1005.Pp 1006where expression consists of all characters until the matching 1007.Dq Li } . 1008Any 1009.Dq Li } 1010escaped by a backslash or within a quoted string, and characters in 1011embedded arithmetic expansions, command substitutions, and variable 1012expansions, are not examined in determining the matching 1013.Dq Li } . 1014.Pp 1015The simplest form for parameter expansion is: 1016.Bd -literal -offset indent 1017${parameter} 1018.Ed 1019.Pp 1020The value, if any, of parameter is substituted. 1021.Pp 1022The parameter name or symbol can be enclosed in braces, which are 1023optional except for positional parameters with more than one digit or 1024when parameter is followed by a character that could be interpreted as 1025part of the name. 1026If a parameter expansion occurs inside double-quotes: 1027.Bl -enum 1028.It 1029Pathname expansion is not performed on the results of the 1030expansion. 1031.It 1032Field splitting is not performed on the results of the 1033expansion, with the exception of the special parameter 1034.Li @ . 1035.El 1036.Pp 1037In addition, a parameter expansion can be modified by using one of the 1038following formats. 1039.Bl -tag -width indent 1040.It Li ${parameter:-word} 1041Use Default Values. If parameter is unset or 1042null, the expansion of word is 1043substituted; otherwise, the value of 1044parameter is substituted. 1045.It Li ${parameter:=word} 1046Assign Default Values. If parameter is unset 1047or null, the expansion of word is 1048assigned to parameter. In all cases, the 1049final value of parameter is 1050substituted. Only variables, not positional 1051parameters or special parameters, can be 1052assigned in this way. 1053.It Li ${parameter:?[word]} 1054Indicate Error if Null or Unset. If 1055parameter is unset or null, the expansion of 1056word (or a message indicating it is unset if 1057word is omitted) is written to standard 1058error and the shell exits with a nonzero 1059exit status. 1060Otherwise, the value of 1061parameter is substituted. An 1062interactive shell need not exit. 1063.It Li ${parameter:+word} 1064Use Alternate Value. If parameter is unset 1065or null, null is substituted; 1066otherwise, the expansion of word is 1067substituted. 1068.Pp 1069In the parameter expansions shown previously, use of the colon in the 1070format results in a test for a parameter that is unset or null; omission 1071of the colon results in a test for a parameter that is only unset. 1072.It Li ${#parameter} 1073String Length. The length in characters of 1074the value of parameter. 1075.El 1076.Pp 1077The following four varieties of parameter expansion provide for substring 1078processing. 1079In each case, pattern matching notation 1080(see 1081.Sx Shell Patterns ) , 1082rather than regular expression notation, 1083is used to evaluate the patterns. 1084If parameter is one of the special parameters 1085.Li * 1086or 1087.Li @ , 1088the result of the expansion is unspecified. 1089Enclosing the full parameter expansion string in double-quotes does not 1090cause the following four varieties of pattern characters to be quoted, 1091whereas quoting characters within the braces has this effect. 1092.Bl -tag -width indent 1093.It Li ${parameter%word} 1094Remove Smallest Suffix Pattern. The word 1095is expanded to produce a pattern. The 1096parameter expansion then results in 1097parameter, with the smallest portion of the 1098suffix matched by the pattern deleted. 1099.It Li ${parameter%%word} 1100Remove Largest Suffix Pattern. The word 1101is expanded to produce a pattern. The 1102parameter expansion then results in 1103parameter, with the largest portion of the 1104suffix matched by the pattern deleted. 1105.It Li ${parameter#word} 1106Remove Smallest Prefix Pattern. The word 1107is expanded to produce a pattern. The 1108parameter expansion then results in 1109parameter, with the smallest portion of the 1110prefix matched by the pattern deleted. 1111.It Li ${parameter##word} 1112Remove Largest Prefix Pattern. The word 1113is expanded to produce a pattern. The 1114parameter expansion then results in 1115parameter, with the largest portion of the 1116prefix matched by the pattern deleted. 1117.El 1118.Ss Command Substitution 1119Command substitution allows the output of a command to be substituted in 1120place of the command name itself. Command substitution occurs when 1121the command is enclosed as follows: 1122.Bd -literal -offset indent 1123$(command) 1124.Ed 1125.Pp 1126or the backquoted version: 1127.Bd -literal -offset indent 1128`command` 1129.Ed 1130.Pp 1131The shell expands the command substitution by executing command in a 1132subshell environment and replacing the command substitution 1133with the standard output of the command, 1134removing sequences of one or more newlines at the end of the substitution. 1135Embedded newlines before the end of the output are not removed; 1136however, during field splitting, they may be translated into spaces 1137depending on the value of 1138.Ev IFS 1139and the quoting that is in effect. 1140.Ss Arithmetic Expansion 1141Arithmetic expansion provides a mechanism for evaluating an arithmetic 1142expression and substituting its value. 1143The format for arithmetic expansion is as follows: 1144.Bd -literal -offset indent 1145$((expression)) 1146.Ed 1147.Pp 1148The expression is treated as if it were in double-quotes, except 1149that a double-quote inside the expression is not treated specially. The 1150shell expands all tokens in the expression for parameter expansion, 1151command substitution, and quote removal. 1152.Pp 1153Next, the shell treats this as an arithmetic expression and 1154substitutes the value of the expression. 1155.Ss White Space Splitting (Field Splitting) 1156After parameter expansion, command substitution, and 1157arithmetic expansion the shell scans the results of 1158expansions and substitutions that did not occur in double-quotes for 1159field splitting and multiple fields can result. 1160.Pp 1161The shell treats each character of the 1162.Ev IFS 1163as a delimiter and uses 1164the delimiters to split the results of parameter expansion and command 1165substitution into fields. 1166.Ss Pathname Expansion (File Name Generation) 1167Unless the 1168.Fl f 1169option is set, 1170file name generation is performed 1171after word splitting is complete. Each word is 1172viewed as a series of patterns, separated by slashes. The 1173process of expansion replaces the word with the names of 1174all existing files whose names can be formed by replacing 1175each pattern with a string that matches the specified pattern. 1176There are two restrictions on this: first, a pattern cannot match 1177a string containing a slash, and second, 1178a pattern cannot match a string starting with a period 1179unless the first character of the pattern is a period. 1180The next section describes the patterns used for both 1181Pathname Expansion and the 1182.Ic case 1183command. 1184.Ss Shell Patterns 1185A pattern consists of normal characters, which match themselves, 1186and meta-characters. 1187The meta-characters are 1188.Dq Li \&! , 1189.Dq Li * , 1190.Dq Li \&? , 1191and 1192.Dq Li [ . 1193These characters lose their special meanings if they are quoted. 1194When command or variable substitution is performed and the dollar sign 1195or back quotes are not double-quoted, the value of the 1196variable or the output of the command is scanned for these 1197characters and they are turned into meta-characters. 1198.Pp 1199An asterisk 1200.Pq Li * 1201matches any string of characters. 1202A question mark 1203.Pq Li \&? 1204matches any single character. 1205A left bracket 1206.Pq Li [ 1207introduces a character class. 1208The end of the character class is indicated by a 1209.Dq Li \&] ; 1210if the 1211.Dq Li \&] 1212is missing then the 1213.Dq Li [ 1214matches a 1215.Dq Li [ 1216rather than introducing a character class. 1217A character class matches any of the characters between the square brackets. 1218A range of characters may be specified using a minus sign. 1219The character class may be complemented by making an exclamation point 1220.Pq Li !\& 1221the first character of the character class. 1222.Pp 1223To include a 1224.Dq Li \&] 1225in a character class, make it the first character listed 1226(after the 1227.Dq Li \&! , 1228if any). 1229To include a 1230.Dq Li - , 1231make it the first or last character listed. 1232.Ss Builtin Commands 1233This section lists the commands which 1234are builtin because they need to perform some operation 1235that cannot be performed by a separate process. In addition to 1236these, a builtin version of the 1237.Xr test 1 1238command is provided for efficiency. 1239.Bl -tag -width indent 1240.It Ic \&: 1241A null command that returns a 0 (true) exit value. 1242.It Ic \&. Ar file 1243The commands in the specified file are read and executed by the shell. 1244If 1245.Ar file 1246contains any 1247.Dq / 1248characters, it is used as is. Otherwise, the shell searches the 1249.Ev PATH 1250for the file. If it is not found in the 1251.Ev PATH , 1252it is sought in the current working directory. 1253.It Ic alias Op Ar name ... 1254.It Ic alias Op Ar name Ns = Ns Ar string ... 1255If 1256.Ar name Ns = Ns Ar string 1257is specified, the shell defines the alias 1258.Ar name 1259with value 1260.Ar string . 1261If just 1262.Ar name 1263is specified, the value of the alias 1264.Ar name 1265is printed. 1266With no arguments, the 1267.Ic alias 1268builtin command prints the names and values of all defined aliases 1269(see 1270.Ic unalias ) . 1271Alias values are written with appropriate quoting so that they are 1272suitable for reinput to the shell. 1273.It Ic bg Op Ar job ... 1274Continue the specified jobs 1275(or the current job if no jobs are given) 1276in the background.
|
1356.Ic echo 1357.Op Fl e | Fl n 1358.Op Ar string 1359.Xc 1360Print 1361.Ar string 1362to the standard output with a newline appended. 1363.Bl -tag -width indent 1364.It Fl n 1365Suppress the output of the trailing newline. 1366.It Fl e 1367Process C-style backslash escape sequences. 1368.Ic echo 1369understands the following character escapes: 1370.Bl -tag -width indent 1371.It \ea 1372Alert (ring the terminal bell) 1373.It \eb 1374Backspace 1375.It \ec 1376Suppress the trailing newline (this has the side-effect of truncating the 1377line if it is not the last character) 1378.It \ee 1379The ESC character (ASCII 0x1b) 1380.It \ef 1381Formfeed 1382.It \en 1383Newline 1384.It \er 1385Carriage return 1386.It \et 1387Horizontal tab 1388.It \ev 1389Vertical tab 1390.It \e\e 1391Literal backslash 1392.It \e0nnn 1393(Zero) The character whose octal value is nnn 1394.El 1395.Pp 1396If 1397.Ar string 1398is not enclosed in quotes then the backslash itself must be escaped 1399with a backslash to protect it from the shell. For example 1400.Bd -literal -offset indent 1401$ echo -e "a\evb" 1402a 1403 b 1404$ echo -e a\e\evb 1405a 1406 b 1407$ echo -e "a\e\eb" 1408a\eb 1409$ echo -e a\e\e\e\eb 1410a\eb 1411.Ed 1412.El 1413.Pp 1414Only one of the 1415.Fl e 1416and 1417.Fl n 1418options may be specified. 1419.It Ic eval Ar string ... 1420Concatenate all the arguments with spaces. 1421Then re-parse and execute the command. 1422.It Ic exec Op Ar command Op arg ... 1423Unless 1424.Ar command 1425is omitted, 1426the shell process is replaced with the specified program 1427(which must be a real program, not a shell builtin command or function). 1428Any redirections on the 1429.Ic exec 1430command are marked as permanent, 1431so that they are not undone when the 1432.Ic exec 1433command finishes. 1434.It Ic exit Op Ar exitstatus 1435Terminate the shell process. 1436If 1437.Ar exitstatus 1438is given 1439it is used as the exit status of the shell; 1440otherwise the exit status of the preceding command is used. 1441.It Xo 1442.Ic export 1443.Op Fl p 1444.Op Ar name ... 1445.Xc 1446The specified names are exported so that they will 1447appear in the environment of subsequent commands. 1448The only way to un-export a variable is to 1449.Ic unset 1450it. 1451The shell allows the value of a variable to be set 1452at the same time as it is exported by writing 1453.Bd -literal -offset indent 1454export name=value 1455.Ed 1456.Pp 1457With no arguments the export command lists the names 1458of all exported variables. 1459If the 1460.Fl p 1461option is specified, the exported variables are printed as 1462.Dq Ic export Ar name Ns = Ns Ar value 1463lines, suitable for re-input to the shell. 1464.It Ic fc Oo Fl e Ar editor Oc Op Ar first Op Ar last 1465.It Ic fc Fl l Oo Fl nr Oc Op Ar first Op Ar last 1466.It Ic fc Fl s Oo Ar old Ns = Ns Ar new Oc Op Ar first 1467The 1468.Ic fc 1469builtin command lists, or edits and re-executes, 1470commands previously entered to an interactive shell. 1471.Bl -tag -width indent 1472.It Fl e Ar editor 1473Use the editor named by 1474.Ar editor 1475to edit the commands. 1476The editor string is a command name, 1477subject to search via the 1478.Ev PATH 1479variable. 1480The value in the 1481.Ev FCEDIT 1482variable is used as a default when 1483.Fl e 1484is not specified. 1485If 1486.Ev FCEDIT 1487is null or unset, the value of the 1488.Ev EDITOR 1489variable is used. 1490If 1491.Ev EDITOR 1492is null or unset, 1493.Xr ed 1 1494is used as the editor. 1495.It Fl l No (ell) 1496List the commands rather than invoking 1497an editor on them. The commands are written in the 1498sequence indicated by the first and last operands, as 1499affected by 1500.Fl r , 1501with each command preceded by the command number. 1502.It Fl n 1503Suppress command numbers when listing with 1504.Fl l . 1505.It Fl r 1506Reverse the order of the commands listed 1507(with 1508.Fl l ) 1509or edited 1510(with neither 1511.Fl l 1512nor 1513.Fl s ) . 1514.It Fl s 1515Re-execute the command without invoking an editor. 1516.It Ar first 1517.It Ar last 1518Select the commands to list or edit. 1519The number of previous commands that can be accessed 1520are determined by the value of the 1521.Ev HISTSIZE 1522variable. 1523The value of 1524.Ar first 1525or 1526.Ar last 1527or both are one of the following: 1528.Bl -tag -width indent 1529.It Ar [+]num 1530A positive number representing a command number; 1531command numbers can be displayed with the 1532.Fl l 1533option. 1534.It Ar -num 1535A negative decimal number representing the 1536command that was executed 1537.Ar num 1538of 1539commands previously. 1540For example, -1 is the immediately previous command. 1541.It Ar string 1542A string indicating the most recently entered command 1543that begins with that string. 1544If the 1545.Ar old=new 1546operand is not also specified with 1547.Fl s , 1548the string form of the first operand cannot contain an embedded equal sign. 1549.El 1550.El 1551.Pp 1552The following environment variables affect the execution of 1553.Ic fc : 1554.Bl -tag -width indent 1555.It Ev FCEDIT 1556Name of the editor to use. 1557.It Ev HISTSIZE 1558The number of previous commands that are accessible. 1559.El 1560.It Ic fg Op Ar job 1561Move the specified 1562.Ar job 1563or the current job to the foreground. 1564.It Ic getopts Ar optstring Ar var 1565The POSIX 1566.Ic getopts 1567command. 1568The 1569.Ic getopts 1570command deprecates the older 1571.Xr getopt 1 1572command. 1573The first argument should be a series of letters, each possibly 1574followed by a colon which indicates that the option takes an argument. 1575The specified variable is set to the parsed option. The index of 1576the next argument is placed into the shell variable 1577.Ev OPTIND . 1578If an option takes an argument, it is placed into the shell variable 1579.Ev OPTARG . 1580If an invalid option is encountered, 1581.Ev var 1582is set to 1583.Dq Li \&? . 1584It returns a false value (1) when it encounters the end of the options. 1585.It Ic hash Oo Fl rv Oc Op Ar command ... 1586The shell maintains a hash table which remembers the locations of commands. 1587With no arguments whatsoever, the 1588.Ic hash 1589command prints out the contents of this table. 1590Entries which have not been looked at since the last 1591.Ic cd 1592command are marked with an asterisk; 1593it is possible for these entries to be invalid. 1594.Pp 1595With arguments, the 1596.Ic hash 1597command removes each specified 1598.Ar command 1599from the hash table (unless they are functions) and then locates it. 1600With the 1601.Fl v 1602option, 1603.Ic hash 1604prints the locations of the commands as it finds them. 1605The 1606.Fl r 1607option causes the 1608.Ic hash 1609command to delete all the entries in the hash table except for functions. 1610.It Ic jobid Op Ar job 1611Print the process id's of the processes in the specified 1612.Ar job . 1613If the 1614.Ar job 1615argument is omitted, use the current job. 1616.It Xo 1617.Ic jobs 1618.Op Fl ls 1619.Op Ar job ... 1620.Xc 1621Print information about the specified jobs, or all jobs if no 1622.Ar job 1623argument is given. 1624The information printed includes job ID, status and command name. 1625.Pp 1626If the 1627.Fl l 1628option is specified, the PID of each job is also printed. 1629If the 1630.Fl s 1631option is specified, only the PID's of the jobs are printed, one per line. 1632.It Ic pwd Op Fl LP 1633Print the path of the current directory. The builtin command may 1634differ from the program of the same name because the 1635builtin command remembers what the current directory 1636is rather than recomputing it each time. This makes 1637it faster. However, if the current directory is 1638renamed, 1639the builtin version of 1640.Xr pwd 1 1641will continue to print the old name for the directory. 1642.Pp 1643If the 1644.Fl P 1645option is specified, symbolic links are resolved. 1646If the 1647.Fl L 1648option is specified, the shell's notion of the current directory 1649is printed (symbolic links are not resolved). 1650This is the default. 1651.It Ic read Oo Fl p Ar prompt Oc Oo Fl t Ar timeout Oc Oo Fl er Oc Ar variable ... 1652The 1653.Ar prompt 1654is printed if the 1655.Fl p 1656option is specified 1657and the standard input is a terminal. Then a line is 1658read from the standard input. The trailing newline 1659is deleted from the line and the line is split as 1660described in the section on 1661.Sx White Space Splitting (Field Splitting) 1662above, and 1663the pieces are assigned to the variables in order. 1664If there are more pieces than variables, the remaining 1665pieces (along with the characters in 1666.Ev IFS 1667that separated them) 1668are assigned to the last variable. 1669If there are more variables than pieces, the remaining 1670variables are assigned the null string. 1671.Pp 1672Backslashes are treated specially, unless the 1673.Fl r 1674option is 1675specified. If a backslash is followed by 1676a newline, the backslash and the newline will be 1677deleted. If a backslash is followed by any other 1678character, the backslash will be deleted and the following 1679character will be treated as though it were not in 1680.Ev IFS , 1681even if it is. 1682.Pp 1683If the 1684.Fl t 1685option is specified and the 1686.Ar timeout 1687elapses before any input is supplied, 1688the 1689.Ic read 1690command will return without assigning any values. 1691The 1692.Ar timeout 1693value may optionally be followed by one of 1694.Dq s , 1695.Dq m 1696or 1697.Dq h 1698to explicitly specify seconds, minutes or hours. 1699If none is supplied, 1700.Dq s 1701is assumed. 1702.Pp 1703The 1704.Fl e 1705option exists only for backward compatibility with older scripts. 1706.It Xo 1707.Ic readonly 1708.Op Fl p 1709.Op Ar name ... 1710.Xc 1711Each specified 1712.Ar name 1713is marked as read only, 1714so that it cannot be subsequently modified or unset. 1715The shell allows the value of a variable to be set 1716at the same time as it is marked read only 1717by using the following form: 1718.Bd -literal -offset indent 1719readonly name=value 1720.Ed 1721.Pp 1722With no arguments the 1723.Ic readonly 1724command lists the names of all read only variables. 1725If the 1726.Fl p 1727option is specified, the read-only variables are printed as 1728.Dq Ic readonly Ar name Ns = Ns Ar value 1729lines, suitable for re-input to the shell. 1730.It Ic set Oo Fl /+abCEefIimnpTuVvx Oc Oo Fl /+o Ar longname Oc Oo 1731.Fl c Ar string Oc Op Fl - Ar arg ... 1732The 1733.Ic set 1734command performs three different functions: 1735.Bl -item 1736.It 1737With no arguments, it lists the values of all shell variables. 1738.It 1739If options are given, 1740either in short form or using the long 1741.Dq Fl /+o Ar longname 1742form, 1743it sets or clears the specified options as described in the section called 1744.Sx Argument List Processing . 1745.It 1746If the 1747.Dq Fl - 1748option is specified, 1749.Ic set 1750will replace the shell's positional parameters with the subsequent 1751arguments. 1752If no arguments follow the 1753.Dq Fl - 1754option, 1755all the positional parameters will be cleared, 1756which is equivalent to executing the command 1757.Dq Li shift $# . 1758The 1759.Dq Fl - 1760flag may be ommitted when specifying arguments to be used 1761as positional replacement parameters. 1762This is not recommended, 1763because the first argument may begin with a dash 1764.Pq Li - 1765or a plus 1766.Pq Li + , 1767which the 1768.Ic set 1769command will interpret as a request to enable or disable options. 1770.El 1771.It Ic setvar Ar variable Ar value 1772Assigns the specified 1773.Ar value 1774to the specified 1775.Ar variable . 1776.Ic Setvar 1777is intended to be used in functions that 1778assign values to variables whose names are passed as parameters. 1779In general it is better to write 1780.Bd -literal -offset indent 1781variable=value 1782.Ed 1783rather than using 1784.Ic setvar . 1785.It Ic shift Op Ar n 1786Shift the positional parameters 1787.Ar n 1788times, or once if 1789.Ar n 1790is not specified. 1791A shift sets the value of $1 to the value of $2, 1792the value of $2 to the value of $3, and so on, 1793decreasing the value of $# by one. 1794If there are zero positional parameters, shifting does not do anything. 1795.It Ic trap Oo Ar action Oc Ar signal ... 1796Cause the shell to parse and execute 1797.Ar action 1798when any specified 1799.Ar signal 1800is received. 1801The signals are specified by signal number. 1802The 1803.Ar action 1804may be null or omitted; 1805the former causes the specified signal to be ignored 1806and the latter causes the default action to be taken. 1807When the shell forks off a subshell, 1808it resets trapped (but not ignored) signals to the default action. 1809The 1810.Ic trap 1811command has no effect on signals that were ignored on entry to the shell. 1812.It Ic type Op Ar name ... 1813Interpret each 1814.Ar name 1815as a command and print the resolution of the command search. 1816Possible resolutions are: 1817shell keyword, alias, shell builtin command, command, tracked alias 1818and not found. 1819For aliases the alias expansion is printed; 1820for commands and tracked aliases 1821the complete pathname of the command is printed. 1822.It Ic ulimit Oo Fl HSabcdflmnstuv Oc Op Ar limit 1823Set or display resource limits (see 1824.Xr getrlimit 2 ) . 1825If 1826.Ar limit 1827is specified, the named resource will be set; 1828otherwise the current resource value will be displayed. 1829.Pp 1830If 1831.Fl H 1832is specified, the hard limits will be set or displayed. 1833While everybody is allowed to reduce a hard limit, 1834only the superuser can increase it. 1835The 1836.Fl S 1837option 1838specifies the soft limits instead. When displaying limits, 1839only one of 1840.Fl S 1841or 1842.Fl H 1843can be given. 1844The default is to display the soft limits, 1845and to set both the hard and the soft limits. 1846.Pp 1847Option 1848.Fl a 1849causes the 1850.Ic ulimit 1851command to display all resources. 1852The parameter 1853.Ar limit 1854is not acceptable in this mode. 1855.Pp 1856The remaining options specify which resource value is to be 1857displayed or modified. 1858They are mutually exclusive. 1859.Bl -tag -width indent 1860.It Fl b Ar sbsize 1861The maximum size of socket buffer usage, in bytes. 1862.It Fl c Ar coredumpsize 1863The maximal size of core dump files, in 512-byte blocks. 1864.It Fl d Ar datasize 1865The maximal size of the data segment of a process, in kilobytes. 1866.It Fl f Ar filesize 1867The maximal size of a file, in 512-byte blocks. 1868.It Fl l Ar lockedmem 1869The maximal size of memory that can be locked by a process, in 1870kilobytes. 1871.It Fl m Ar memoryuse 1872The maximal resident set size of a process, in kilobytes. 1873.It Fl n Ar nofiles 1874The maximal number of descriptors that could be opened by a process. 1875.It Fl s Ar stacksize 1876The maximal size of the stack segment, in kilobytes. 1877.It Fl t Ar time 1878The maximal amount of CPU time to be used by each process, in seconds. 1879.It Fl u Ar userproc 1880The maximal number of simultaneous processes for this user ID. 1881.It Fl v Ar virtualmem 1882The maximal virtual size of a process, in kilobytes. 1883.El 1884.It Ic umask Op Ar mask 1885Set the file creation mask (see 1886.Xr umask 2 ) 1887to the octal value specified by 1888.Ar mask . 1889If the argument is omitted, the current mask value is printed. 1890.It Ic unalias Oo Fl a Oc Op Ar name 1891If 1892.Ar name 1893is specified, the shell removes that alias. 1894If 1895.Fl a 1896is specified, all aliases are removed. 1897.It Xo 1898.Ic unset 1899.Op Fl fv 1900.Ar name ... 1901.Xc 1902The specified variables or functions are unset and unexported. 1903If the 1904.Fl v 1905option is specified or no options are given, the 1906.Ar name 1907arguments are treated as variable names. 1908If the 1909.Fl f 1910option is specified, the 1911.Ar name 1912arguments are treated as function names. 1913.It Ic wait Op Ar job 1914Wait for the specified 1915.Ar job 1916to complete and return the exit status of the last process in the 1917.Ar job . 1918If the argument is omitted, wait for all jobs to complete 1919and return an exit status of zero. 1920.El 1921.Ss Commandline Editing 1922When 1923.Nm 1924is being used interactively from a terminal, the current command 1925and the command history 1926(see 1927.Ic fc 1928in 1929.Sx Builtin Commands ) 1930can be edited using vi-mode command line editing. 1931This mode uses commands similar 1932to a subset of those described in the vi man page. 1933The command 1934.Dq Li set -o vi 1935(or 1936.Dq Li set -V ) 1937enables vi-mode editing and places 1938.Nm 1939into vi insert mode. With vi-mode enabled, 1940.Nm 1941can be switched between insert mode and command mode by typing 1942.Aq ESC . 1943Hitting 1944.Aq return 1945while in command mode will pass the line to the shell. 1946.Pp 1947Similarly, the 1948.Dq Li set -o emacs 1949(or 1950.Dq Li set -E ) 1951command can be used to enable a subset of 1952emacs-style command line editing features. 1953.Sh SEE ALSO 1954.Xr builtin 1 , 1955.Xr echo 1 , 1956.Xr expr 1 , 1957.Xr pwd 1 , 1958.Xr test 1 1959.Sh HISTORY 1960A 1961.Nm 1962command appeared in 1963.At v1 .
|