Thu Mar 31 16:18:23 2016 UTC ()
Document the NETBSD_SHELL variable, the enhancements to export,
the posix option, and a whole bunch of miscellaneous updates and
corrections. (from kre@)


(christos)
diff -r1.119 -r1.120 src/bin/sh/sh.1

cvs diff -r1.119 -r1.120 src/bin/sh/sh.1 (expand / switch to unified diff)

--- src/bin/sh/sh.1 2016/02/24 15:28:36 1.119
+++ src/bin/sh/sh.1 2016/03/31 16:18:22 1.120
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1.\" $NetBSD: sh.1,v 1.119 2016/02/24 15:28:36 wiz Exp $ 1.\" $NetBSD: sh.1,v 1.120 2016/03/31 16:18:22 christos Exp $
2.\" Copyright (c) 1991, 1993 2.\" Copyright (c) 1991, 1993
3.\" The Regents of the University of California. All rights reserved. 3.\" The Regents of the University of California. All rights reserved.
4.\" 4.\"
5.\" This code is derived from software contributed to Berkeley by 5.\" This code is derived from software contributed to Berkeley by
6.\" Kenneth Almquist. 6.\" Kenneth Almquist.
7.\" 7.\"
8.\" Redistribution and use in source and binary forms, with or without 8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions 9.\" modification, are permitted provided that the following conditions
10.\" are met: 10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright 11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer. 12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the 14.\" notice, this list of conditions and the following disclaimer in the
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE. 30.\" SUCH DAMAGE.
31.\" 31.\"
32.\" @(#)sh.1 8.6 (Berkeley) 5/4/95 32.\" @(#)sh.1 8.6 (Berkeley) 5/4/95
33.\" 33.\"
34.Dd January 5, 2015 34.Dd March 31, 2016
35.Dt SH 1 35.Dt SH 1
36.ds flags abCEeFfhnuvxIimpqV 36.ds flags abCEeFfhnuvxIimpqV
37.Os 37.Os
38.Sh NAME 38.Sh NAME
39.Nm sh 39.Nm sh
40.Nd command interpreter (shell) 40.Nd command interpreter (shell)
41.Sh SYNOPSIS 41.Sh SYNOPSIS
42.Nm 42.Nm
43.Bk -words 43.Bk -words
44.Op Fl \*[flags] 44.Op Fl \*[flags]
45.Op Cm +\*[flags] 45.Op Cm +\*[flags]
46.Ek 46.Ek
47.Bk -words 47.Bk -words
@@ -320,48 +320,66 @@ instead of attempting @@ -320,48 +320,66 @@ instead of attempting
320.Xr vfork 2 320.Xr vfork 2
321when it needs to create a new process. 321when it needs to create a new process.
322This should normally have no visible effect, 322This should normally have no visible effect,
323but can slow execution. 323but can slow execution.
324The 324The
325.Nm 325.Nm
326can be compiled to always use 326can be compiled to always use
327.Xr fork 2 327.Xr fork 2
328in which case altering the 328in which case altering the
329.Fl F 329.Fl F
330flag has no effect. 330flag has no effect.
331.It Fl h Em trackall 331.It Fl h Em trackall
332Bind commands in functions to file system paths when the function is defined. 332Bind commands in functions to file system paths when the function is defined.
 333.\" They can seek me here (that dreaded filesystem)
333When off, 334When off,
334the file system is searched for commands each time the function is invoked. 335the file system is searched for commands each time the function is invoked.
335(Not implemented.) 336(Not implemented.)
 337.\" then can seek me there (the filesystem, once again)
336.It Fl p Em nopriv 338.It Fl p Em nopriv
337Do not attempt to reset effective uid if it does not match uid. 339Do not attempt to reset effective uid if it does not match uid.
338This is not set by default to help avoid incorrect usage by setuid 340This is not set by default to help avoid incorrect usage by setuid
339root programs via 341root programs via
340.Xr system 3 342.Xr system 3
341or 343or
342.Xr popen 3 . 344.Xr popen 3 .
343.It "\ \ " Em cdprint 345.It "\ \ " Em cdprint
344Make an interactive shell always print the new directory name when 346Make an interactive shell always print the new directory name when
345changed by the 347changed by the
346.Ic cd 348.Ic cd
347command. 349command.
348.It "\ \ " Em nolog 350.It "\ \ " Em nolog
349Prevent the entry of function definitions into the command history (see 351Prevent the entry of function definitions into the command history (see
350.Ic fc 352.Ic fc
351in the 353in the
352.Sx Built-ins 354.Sx Built-ins
353section.) 355section.)
354(Not implemented.) 356(Not implemented.)
 357.It "\ \ " Em posix
 358Enables closer adherence to the shell standard.
 359This option will default set at shell startup if the
 360environment variable
 361.Ev POSIXLY_CORRECT
 362is present.
 363That can be overridden by the
 364.Fl o
 365option on the command line.
 366Currently this option controls whether (!posix) or not (posix)
 367the file given by the
 368.Ev ENV
 369variable is read at startup by a non-interactive shell.
 370Consequently, while it can be manipulated by the
 371.Ic set
 372command, doing so has no current purpose.
355.It "\ \ " Em tabcomplete 373.It "\ \ " Em tabcomplete
356Enables filename completion in the command line editor. 374Enables filename completion in the command line editor.
357Typing a tab character will extend the current input word to match a 375Typing a tab character will extend the current input word to match a
358filename. 376filename.
359If more than one filename matches it is only extended to be the common prefix. 377If more than one filename matches it is only extended to be the common prefix.
360Typing a second tab character will list all the matching names. 378Typing a second tab character will list all the matching names.
361One of the editing modes, either 379One of the editing modes, either
362.Fl E 380.Fl E
363or 381or
364.Fl V , 382.Fl V ,
365must be enabled for this to work. 383must be enabled for this to work.
366.El 384.El
367.Ss Lexical Structure 385.Ss Lexical Structure
@@ -518,62 +536,70 @@ Close standard output (or n). @@ -518,62 +536,70 @@ Close standard output (or n).
518.It [n] Ns \*[Lt]\*[Gt] file 536.It [n] Ns \*[Lt]\*[Gt] file
519Open file for reading and writing on standard input (or n). 537Open file for reading and writing on standard input (or n).
520.El 538.El
521.Pp 539.Pp
522The following redirection is often called a 540The following redirection is often called a
523.Dq here-document . 541.Dq here-document .
524.Bl -item -offset indent 542.Bl -item -offset indent
525.It 543.It
526.Li [n]\*[Lt]\*[Lt] delimiter 544.Li [n]\*[Lt]\*[Lt] delimiter
527.Dl here-doc-text ... 545.Dl here-doc-text ...
528.Li delimiter 546.Li delimiter
529.El 547.El
530.Pp 548.Pp
531All the text on successive lines up to the delimiter, or to an EOF, is 549All the text on successive lines up to the delimiter,
 550which must appear on a line by itself, with nothing other
 551than an immediately following newline, is
532saved away and made available to the command on standard input, or file 552saved away and made available to the command on standard input, or file
533descriptor n if it is specified. 553descriptor n if it is specified.
534If the delimiter as specified on the initial line is 554If the delimiter as specified on the initial line is
535quoted, then the here-doc-text is treated literally; otherwise, the text is 555quoted, then the here-doc-text is treated literally; otherwise, the text is
536subjected to parameter expansion, command substitution, and arithmetic 556subjected to parameter expansion, command substitution, and arithmetic
537expansion as described in the 557expansion as described in the
538.Sx Word Expansions 558.Sx Word Expansions
539section below. 559section below.
540If the operator is 560If the operator is
541.Dq \*[Lt]\*[Lt]- 561.Dq \*[Lt]\*[Lt]\(mi
542instead of 562instead of
543.Dq \*[Lt]\*[Lt] , 563.Dq \*[Lt]\*[Lt] ,
544then leading tabs in the here-doc-text are stripped. 564then leading tabs in all lines in the here-doc-text, including before the
 565end delimiter, are stripped.
 566If the delimiter is not quoted, lines in here-doc-text that end with
 567an unquoted \e are joined to the following line, the \e and following
 568newline are simply removed while reading the here-doc, which thus guarantees
 569that neither of those lines can be the end delimiter.
545.Ss Search and Execution 570.Ss Search and Execution
546There are three types of commands: shell functions, built-in commands, and 571There are three types of commands: shell functions, built-in commands, and
547normal programs -- and the command is searched for (by name) in that order. 572normal programs -- and the command is searched for (by name) in that order.
548They each are executed in a different way. 573They each are executed in a different way.
549.Pp 574.Pp
550When a shell function is executed, all of the shell positional parameters 575When a shell function is executed, all of the shell positional parameters
551(except $0, which remains unchanged) are set to the arguments of the shell 576(except $0, which remains unchanged) are set to the arguments of the shell
552function. 577function.
553The variables which are explicitly placed in the environment of 578The variables which are explicitly placed in the environment of
554the command (by placing assignments to them before the function name) are 579the command (by placing assignments to them before the function name) are
555made local to the function and are set to the values given. 580made local to the function and are set to the values given.
556Then the command given in the function definition is executed. 581Then the command given in the function definition is executed.
557The positional parameters are restored to their original values 582The positional parameters are restored to their original values
558when the command completes. 583when the command completes.
559This all occurs within the current shell. 584This all occurs within the current shell.
560.Pp 585.Pp
561Shell built-ins are executed internally to the shell, without spawning a 586Shell built-ins are executed internally to the shell, without spawning a
562new process. 587new process.
563.Pp 588.Pp
564Otherwise, if the command name doesn't match a function or built-in, the 589Otherwise, if the command name doesn't match a function or built-in, the
565command is searched for as a normal program in the file system (as 590command is searched for as a normal program in the file system (as
566described in the next section). 591described in the next section).
 592.\" But the damned elusive filesystem shall never be defeated!
567When a normal program is executed, the shell runs the program, 593When a normal program is executed, the shell runs the program,
568passing the arguments and the environment to the program. 594passing the arguments and the environment to the program.
569If the program is not a normal executable file (i.e., if it does 595If the program is not a normal executable file (i.e., if it does
570not begin with the "magic number" whose 596not begin with the "magic number" whose
571.Tn ASCII 597.Tn ASCII
572representation is "#!", so 598representation is "#!", so
573.Xr execve 2 599.Xr execve 2
574returns 600returns
575.Er ENOEXEC 601.Er ENOEXEC
576then) the shell will interpret the program in a subshell. 602then) the shell will interpret the program in a subshell.
577The child shell will reinitialize itself in this case, 603The child shell will reinitialize itself in this case,
578so that the effect will be as if a 604so that the effect will be as if a
579new shell had been invoked to handle the ad-hoc shell script, except that 605new shell had been invoked to handle the ad-hoc shell script, except that
@@ -687,33 +713,38 @@ it executes in the current shell -- but  @@ -687,33 +713,38 @@ it executes in the current shell -- but
687environment is wiped). 713environment is wiped).
688.Ss Background Commands -- \*[Am] 714.Ss Background Commands -- \*[Am]
689If a command is terminated by the control operator ampersand (\*[Am]), the 715If a command is terminated by the control operator ampersand (\*[Am]), the
690shell executes the command asynchronously -- that is, the shell does not 716shell executes the command asynchronously -- that is, the shell does not
691wait for the command to finish before executing the next command. 717wait for the command to finish before executing the next command.
692.Pp 718.Pp
693The format for running a command in background is: 719The format for running a command in background is:
694.Pp 720.Pp
695.Dl command1 \*[Am] [command2 \*[Am] ...] 721.Dl command1 \*[Am] [command2 \*[Am] ...]
696.Pp 722.Pp
697If the shell is not interactive, the standard input of an asynchronous 723If the shell is not interactive, the standard input of an asynchronous
698command is set to 724command is set to
699.Pa /dev/null . 725.Pa /dev/null .
 726The process identifier of the most recent command started in the
 727background can be obtained from the value of the special parameter
 728.Dq \&!
 729(see
 730.Sx Special Parameters ) .
700.Ss Lists -- Generally Speaking 731.Ss Lists -- Generally Speaking
701A list is a sequence of zero or more commands separated by newlines, 732A list is a sequence of zero or more commands separated by newlines,
702semicolons, or ampersands, and optionally terminated by one of these three 733semicolons, or ampersands, and optionally terminated by one of these three
703characters. 734characters.
704The commands in a list are executed in the order they are written. 735The commands in a list are executed in the order they are written.
705If command is followed by an ampersand, the shell starts the 736If command is followed by an ampersand, the shell starts the
706command and immediately proceed onto the next command; otherwise it waits 737command and immediately proceeds to the next command; otherwise it waits
707for the command to terminate before proceeding to the next one. 738for the command to terminate before proceeding to the next one.
708.Ss Short-Circuit List Operators 739.Ss Short-Circuit List Operators
709.Dq \*[Am]\*[Am] 740.Dq \*[Am]\*[Am]
710and 741and
711.Dq || 742.Dq ||
712are AND-OR list operators. 743are AND-OR list operators.
713.Dq \*[Am]\*[Am] 744.Dq \*[Am]\*[Am]
714executes the first command, and then executes the second command if and only 745executes the first command, and then executes the second command if and only
715if the exit status of the first command is zero. 746if the exit status of the first command is zero.
716.Dq || 747.Dq ||
717is similar, but executes the second command if and only if the exit status 748is similar, but executes the second command if and only if the exit status
718of the first command is nonzero. 749of the first command is nonzero.
719.Dq \*[Am]\*[Am] 750.Dq \*[Am]\*[Am]
@@ -750,37 +781,39 @@ The syntax of the while command is @@ -750,37 +781,39 @@ The syntax of the while command is
750while list 781while list
751do list 782do list
752done 783done
753.Ed 784.Ed
754.Pp 785.Pp
755The two lists are executed repeatedly while the exit status of the 786The two lists are executed repeatedly while the exit status of the
756first list is zero. 787first list is zero.
757The until command is similar, but has the word 788The until command is similar, but has the word
758until in place of while, which causes it to 789until in place of while, which causes it to
759repeat until the exit status of the first list is zero. 790repeat until the exit status of the first list is zero.
760.Pp 791.Pp
761The syntax of the for command is 792The syntax of the for command is
762.Bd -literal -offset indent 793.Bd -literal -offset indent
763for variable in word ... 794for variable [ in word ... ]
764do list 795do list
765done 796done
766.Ed 797.Ed
767.Pp 798.Pp
768The words are expanded, and then the list is executed repeatedly with the 799The words are expanded, or "$@" if no words are given,
 800and then the list is executed repeatedly with the
769variable set to each word in turn. 801variable set to each word in turn.
770do and done may be replaced with 802do and done may be replaced with
771.Dq { 803.Dq {
772and 804and
773.Dq } . 805.Dq } ,
 806but doing so is non-standard and not recommended.
774.Pp 807.Pp
775The syntax of the break and continue command is 808The syntax of the break and continue command is
776.Bd -literal -offset indent 809.Bd -literal -offset indent
777break [ num ] 810break [ num ]
778continue [ num ] 811continue [ num ]
779.Ed 812.Ed
780.Pp 813.Pp
781Break terminates the num innermost for or while loops. 814Break terminates the num innermost for or while loops.
782Continue continues with the next iteration of the innermost loop. 815Continue continues with the next iteration of the innermost loop.
783These are implemented as built-in commands. 816These are implemented as built-in commands.
784.Pp 817.Pp
785The syntax of the case command is 818The syntax of the case command is
786.Bd -literal -offset indent 819.Bd -literal -offset indent
@@ -811,88 +844,178 @@ Grouping commands together this way allo @@ -811,88 +844,178 @@ Grouping commands together this way allo
811their output as though they were one program: 844their output as though they were one program:
812.Bd -literal -offset indent 845.Bd -literal -offset indent
813{ echo -n \*q hello \*q ; echo \*q world" ; } \*[Gt] greeting 846{ echo -n \*q hello \*q ; echo \*q world" ; } \*[Gt] greeting
814.Ed 847.Ed
815.Pp 848.Pp
816Note that 849Note that
817.Dq } 850.Dq }
818must follow a control operator (here, 851must follow a control operator (here,
819.Dq \&; ) 852.Dq \&; )
820so that it is recognized as a reserved word and not as another command argument. 853so that it is recognized as a reserved word and not as another command argument.
821.Ss Functions 854.Ss Functions
822The syntax of a function definition is 855The syntax of a function definition is
823.Pp 856.Pp
824.Dl name ( ) command 857.Dl name ( ) command [ redirect... ]
825.Pp 858.Pp
826A function definition is an executable statement; when executed it 859A function definition is an executable statement; when executed it
827installs a function named name and returns an exit status of zero. 860installs a function named name and returns an exit status of zero.
828The command is normally a list enclosed between 861The command is normally a list enclosed between
829.Dq { 862.Dq {
830and 863and
831.Dq } . 864.Dq } .
 865The standard syntax also allows the command to be any of the other
 866compound commands, or a sub-shell, all of which are supported.
 867As an extension, this shell also allows a simple command to be
 868used, though users should be aware this is non-standard syntax.
 869This means that
 870.Dl l() ls "$@"
 871works to make
 872.Dq l
 873an alternative name for the
 874.Ic ls
 875command.
 876.Pp
 877If the optional redirect, (see
 878.Sx Redirections ) ,
 879which may be of any of the normal forms,
 880is given, it is applied each time the
 881function is called.
 882This means that a simple
 883.Dq "Hello World
 884function might be written (in the extended syntax) as:
 885.Dl hello() cat <<EOF
 886.Dl Hello World!
 887.Dl EOF
 888To be correctly standards conforming this should be re-written as:
 889.Dl hello() { cat; } <<EOF
 890.Dl Hello World!
 891.Dl EOF
 892Note the distinction between those forms, and
 893.Dl hello() { cat <<EOF
 894.Dl Hello World!
 895.Dl EOF
 896.Dl \&}
 897which reads and processes the
 898.Ic "here document
 899each time the shell executes the function, and which applies
 900that input only to the cat command, not to any other commands
 901that might appear in the function.
832.Pp 902.Pp
833Variables may be declared to be local to a function by using a local 903Variables may be declared to be local to a function by using a local
834command. 904command.
835This should appear as the first statement of a function, and the syntax is 905This should appear as the first statement of a function, and the syntax is
836.Pp 906.Pp
837.Dl local [ variable | - ] ... 907.Dl local [ variable | - ] ...
838.Pp 908.Pp
839.Dq Local 909.Dq Ic local
840is implemented as a built-in command. 910is implemented as a built-in command.
841.Pp 911.Pp
842When a variable is made local, it inherits the initial value and exported 912When a variable is made local, it inherits the initial value and exported,
 913unexportable,
843and read-only flags from the variable with the same name in the surrounding 914and read-only flags from the variable with the same name in the surrounding
844scope, if there is one. 915scope, if there is one.
845Otherwise, the variable is initially unset. 916Otherwise, the variable is initially unset.
 917Making a read-only variable local is possible, but pointless.
 918If the
 919.Ic readonly
 920command is applied to a variable that has been declared local,
 921the variable cannot be (further) modified within the function,
 922or any other functions it calls, however when the function returns,
 923the previous status (and value) of the variable is returned.
 924.Pp
 925Values may be given to local variables on the
 926.Ic local
 927command line in a similar fashion as used for
 928.Ic export
 929and
 930.Ic readonly .
 931.Pp
846The shell uses dynamic scoping, so that if you make the variable x local to 932The shell uses dynamic scoping, so that if you make the variable x local to
847function f, which then calls function g, references to the variable x made 933function f, which then calls function g, references to the variable x made
848inside g will refer to the variable x declared inside f, not to the global 934inside g will refer to the variable x declared inside f, not to the global
849variable named x. 935variable named x.
850.Pp 936.Pp
 937Note that the parameters $1, $2, ... (see
 938.Sx Positional Parameters ) ,
 939and $#, $* and $@ (see
 940.Sx Special Parameters ) ,
 941are always made local in all functions, and are reset inside the
 942function to represent the options and arguments passed to the function.
 943Note that $0 however retains the value it had outside the function,
 944as do all the other special parameters.
 945.Pp
851The only special parameter that can be made local is 946The only special parameter that can be made local is
852.Dq - . 947.Dq - .
853Making 948Making
854.Dq - 949.Dq -
855local causes any shell options that are changed via the set command inside the 950local causes any shell options that are changed via the set command inside the
856function to be restored to their original values when the function 951function to be restored to their original values when the function
857returns. 952returns.
858.Pp 953.Pp
 954It is a syntax error to use
 955.Ic local
 956outside the scope of a function definition.
 957When used inside a function, it exits with status 0.
 958.Pp
859The syntax of the return command is 959The syntax of the return command is
860.Pp 960.Pp
861.Dl return [ exitstatus ] 961.Dl return [ exitstatus ]
862.Pp 962.Pp
863It terminates the currently executing function. 963It terminates the currently executing function or
 964.Dq \&.
 965script.
864Return is implemented as a built-in command. 966Return is implemented as a built-in command.
 967The exit status of the function (or
 968.Dl \&.
 969command) is either that given on the
 970.Ic return
 971command line, or the value of the special parameter
 972.Dq $?
 973immediately before the return was executed.
865.Ss Variables and Parameters 974.Ss Variables and Parameters
866The shell maintains a set of parameters. 975The shell maintains a set of parameters.
867A parameter denoted by a name is called a variable. 976A parameter denoted by a name is called a variable.
868When starting up, the shell turns all the environment 977When starting up, the shell turns all the environment
869variables into shell variables. 978variables into shell variables.
870New variables can be set using the form 979New variables can be set using the form
871.Pp 980.Pp
872.Dl name=value 981.Dl name=value
873.Pp 982.Pp
874Variables set by the user must have a name consisting solely of 983Variables set by the user must have a name consisting solely of
875alphabetics, numerics, and underscores - the first of which must not be 984alphabetics, numerics, and underscores - the first of which must not be
876numeric. 985numeric.
877A parameter can also be denoted by a number or a special 986A parameter can also be denoted by a number or a special
878character as explained below. 987character as explained below.
879.Ss Positional Parameters 988.Ss Positional Parameters
880A positional parameter is a parameter denoted by a number (n \*[Gt] 0). 989A positional parameter is a parameter denoted by a number (n \*[Gt] 0).
881The shell sets these initially to the values of its command line arguments 990The shell sets these initially to the values of its command line arguments
882that follow the name of the shell script. 991that follow the name of the shell script.
883The 992The
884.Ic set 993.Ic set
885built-in can also be used to set or reset them. 994built-in can also be used to set or reset them, and
 995.Ic shift
 996can be used to manipulate the list.
 997.Pp
 998To refer to the 10th (and later) positional parameters,
 999the form ${n} must be used.
 1000Without the braces, a digit following
 1001.Dq $
 1002can only refer to one of the first 9 positional parameters,
 1003or the special parameter
 1004.Dq 0 .
 1005The word
 1006.Dq $10
 1007is treated identically to
 1008.Dq ${1}0 .
886.Ss Special Parameters 1009.Ss Special Parameters
887A special parameter is a parameter denoted by one of the following special 1010A special parameter is a parameter denoted by one of the following special
888characters. 1011characters.
889The value of the parameter is listed next to its character. 1012The value of the parameter is listed next to its character.
890.Bl -tag -width thinhyphena 1013.Bl -tag -width thinhyphena
891.It * 1014.It *
892Expands to the positional parameters, starting from one. 1015Expands to the positional parameters, starting from one.
893When the 1016When the
894expansion occurs within a double-quoted string it expands to a single 1017expansion occurs within a double-quoted string it expands to a single
895field with the value of each parameter separated by the first character of 1018field with the value of each parameter separated by the first character of
896the 1019the
897.Ev IFS 1020.Ev IFS
898variable, or by a 1021variable, or by a
@@ -926,26 +1049,32 @@ Expands to the number of positional para @@ -926,26 +1049,32 @@ Expands to the number of positional para
926Expands to the exit status of the most recent pipeline. 1049Expands to the exit status of the most recent pipeline.
927.It - (Hyphen.) 1050.It - (Hyphen.)
928Expands to the current option flags (the single-letter 1051Expands to the current option flags (the single-letter
929option names concatenated into a string) as specified on 1052option names concatenated into a string) as specified on
930invocation, by the set built-in command, or implicitly 1053invocation, by the set built-in command, or implicitly
931by the shell. 1054by the shell.
932.It $ 1055.It $
933Expands to the process ID of the invoked shell. 1056Expands to the process ID of the invoked shell.
934A subshell retains the same value of $ as its parent. 1057A subshell retains the same value of $ as its parent.
935.It \&! 1058.It \&!
936Expands to the process ID of the most recent background 1059Expands to the process ID of the most recent background
937command executed from the current shell. 1060command executed from the current shell.
938For a pipeline, the process ID is that of the last command in the pipeline. 1061For a pipeline, the process ID is that of the last command in the pipeline.
 1062If no background commands have yet been started by the shell, then
 1063.Dq \&!
 1064will be unset.
 1065Once set, the value of
 1066.Dq \&!
 1067will be retained until another background command is started.
939.It 0 (Zero.) 1068.It 0 (Zero.)
940Expands to the name of the shell or shell script. 1069Expands to the name of the shell or shell script.
941.El 1070.El
942.Ss Word Expansions 1071.Ss Word Expansions
943This section describes the various expansions that are performed on words. 1072This section describes the various expansions that are performed on words.
944Not all expansions are performed on every word, as explained later. 1073Not all expansions are performed on every word, as explained later.
945.Pp 1074.Pp
946Tilde expansions, parameter expansions, command substitutions, arithmetic 1075Tilde expansions, parameter expansions, command substitutions, arithmetic
947expansions, and quote removals that occur within a single word expand to a 1076expansions, and quote removals that occur within a single word expand to a
948single field. 1077single field.
949It is only field splitting or pathname expansion that can 1078It is only field splitting or pathname expansion that can
950create multiple fields from a single word. 1079create multiple fields from a single word.
951The single exception to this 1080The single exception to this
@@ -1013,27 +1142,27 @@ If a parameter expansion occurs inside d @@ -1013,27 +1142,27 @@ If a parameter expansion occurs inside d
1013Pathname expansion is not performed on the results of the expansion. 1142Pathname expansion is not performed on the results of the expansion.
1014.It 1143.It
1015Field splitting is not performed on the results of the 1144Field splitting is not performed on the results of the
1016expansion, with the exception of the special rules for @. 1145expansion, with the exception of the special rules for @.
1017.El 1146.El
1018.Pp 1147.Pp
1019In addition, a parameter expansion can be modified by using one of the 1148In addition, a parameter expansion can be modified by using one of the
1020following formats. 1149following formats.
1021If the 1150If the
1022.Dq Dv \&: 1151.Dq Dv \&:
1023is omitted in the following modifiers, then the expansion is applied only 1152is omitted in the following modifiers, then the expansion is applied only
1024to unset parameters, not null ones. 1153to unset parameters, not null ones.
1025.Bl -tag -width aaparameterwordaaaaa 1154.Bl -tag -width aaparameterwordaaaaa
1026.It ${parameter:-word} 1155.It ${parameter:\(miword}
1027Use Default Values. 1156Use Default Values.
1028If parameter is unset or null, the expansion of word 1157If parameter is unset or null, the expansion of word
1029is substituted; otherwise, the value of parameter is substituted. 1158is substituted; otherwise, the value of parameter is substituted.
1030.It ${parameter:=word} 1159.It ${parameter:=word}
1031Assign Default Values. 1160Assign Default Values.
1032If parameter is unset or null, the expansion of 1161If parameter is unset or null, the expansion of
1033word is assigned to parameter. 1162word is assigned to parameter.
1034In all cases, the final value of parameter is substituted. 1163In all cases, the final value of parameter is substituted.
1035Only variables, not positional parameters or special 1164Only variables, not positional parameters or special
1036parameters, can be assigned in this way. 1165parameters, can be assigned in this way.
1037.It ${parameter:?[word]} 1166.It ${parameter:?[word]}
1038Indicate Error if Null or Unset. 1167Indicate Error if Null or Unset.
1039If parameter is unset or null, the 1168If parameter is unset or null, the
@@ -1130,44 +1259,72 @@ of the C language, and are evaluated usi @@ -1130,44 +1259,72 @@ of the C language, and are evaluated usi
1130.Ql intmax_t 1259.Ql intmax_t
1131data type (this is an extension to 1260data type (this is an extension to
1132.Tn POSIX , 1261.Tn POSIX ,
1133which requires only 1262which requires only
1134.Ql long 1263.Ql long
1135arithmetic). 1264arithmetic).
1136Shell variables may be referenced by name inside an arithmetic 1265Shell variables may be referenced by name inside an arithmetic
1137expression, without needing a 1266expression, without needing a
1138.Dq \&$ 1267.Dq \&$
1139sign. 1268sign.
1140.Ss White Space Splitting (Field Splitting) 1269.Ss White Space Splitting (Field Splitting)
1141After parameter expansion, command substitution, and 1270After parameter expansion, command substitution, and
1142arithmetic expansion the shell scans the results of 1271arithmetic expansion the shell scans the results of
1143expansions and substitutions that did not occur in double quotes for 1272expansions and substitutions that did not occur in double quotes,
1144field splitting and multiple fields can result. 1273and
 1274.Dq $@
 1275even if it did,
 1276for field splitting and multiple fields can result.
1145.Pp 1277.Pp
1146The shell treats each character of the 1278The shell treats each character of the
1147.Ev IFS 1279.Ev IFS
1148as a delimiter and use the delimiters to split the results of parameter 1280as a delimiter and uses the delimiters to split the results of parameter
1149expansion and command substitution into fields. 1281expansion and command substitution into fields.
1150.Pp 1282.Pp
1151Non-whitespace characters in 1283Non-whitespace characters in
1152.Ev IFS 1284.Ev IFS
1153are treated strictly as parameter terminators. 1285are treated strictly as parameter separators.
1154So adjacent non-whitespace 1286So adjacent non-whitespace
1155.Ev IFS 1287.Ev IFS
1156characters will produce empty parameters. 1288characters will produce empty parameters.
 1289On the other hand, any sequence of whitespace
 1290characters that occur in
 1291.Ev IFS
 1292(known as
 1293.Ev IFS
 1294whitespace)
 1295can occur, leading and trailing
 1296.Ev IFS
 1297whitespace, and
 1298.Ev IFS
 1299whitespace surrounding a non whitespace
 1300.Ev IFS
 1301delimiter, is removed.
 1302Any sequence of
 1303.Ev IFS
 1304whitespace characters without a non-whitespace
 1305.Ev IFS
 1306delimiter acts as a field separator.
1157.Pp 1307.Pp
1158If 1308If
1159.Ev IFS 1309.Ev IFS
1160is unset it is assumed to contain space, tab, and newline. 1310is unset it is assumed to contain space, tab, and newline,
 1311all of which are
 1312.Ev IFS
 1313whitespace characters.
 1314If
 1315.Ev IFS
 1316is set to a null string, there are no delimiters,
 1317and no field splitting occurs.
1161.Ss Pathname Expansion (File Name Generation) 1318.Ss Pathname Expansion (File Name Generation)
1162Unless the 1319Unless the
1163.Fl f 1320.Fl f
1164flag is set, file name generation is performed after word splitting is 1321flag is set, file name generation is performed after word splitting is
1165complete. 1322complete.
1166Each word is viewed as a series of patterns, separated by slashes. 1323Each word is viewed as a series of patterns, separated by slashes.
1167The process of expansion replaces the word with the names of all 1324The process of expansion replaces the word with the names of all
1168existing files whose names can be formed by replacing each pattern with a 1325existing files whose names can be formed by replacing each pattern with a
1169string that matches the specified pattern. 1326string that matches the specified pattern.
1170There are two restrictions on 1327There are two restrictions on
1171this: first, a pattern cannot match a string containing a slash, and 1328this: first, a pattern cannot match a string containing a slash, and
1172second, a pattern cannot match a string starting with a period unless the 1329second, a pattern cannot match a string starting with a period unless the
1173first character of the pattern is a period. 1330first character of the pattern is a period.
@@ -1210,94 +1367,95 @@ matches a @@ -1210,94 +1367,95 @@ matches a
1210.Dq \&[ 1367.Dq \&[
1211rather than introducing a character class. 1368rather than introducing a character class.
1212A character class matches any of the characters between the square brackets. 1369A character class matches any of the characters between the square brackets.
1213A named class of characters (see 1370A named class of characters (see
1214.Xr wctype 3 ) 1371.Xr wctype 3 )
1215may be specified by surrounding the name with 1372may be specified by surrounding the name with
1216.Pq Dq [: 1373.Pq Dq [:
1217and 1374and
1218.Pq Dq :] . 1375.Pq Dq :] .
1219For example, 1376For example,
1220.Pq Dq [[:alpha:]] 1377.Pq Dq [[:alpha:]]
1221is a shell pattern that matches a single letter. 1378is a shell pattern that matches a single letter.
1222A range of characters may be specified using a minus sign 1379A range of characters may be specified using a minus sign
1223.Pq Dq - . 1380.Pq Dq \(mi .
1224The character class may be complemented 1381The character class may be complemented
1225by making an exclamation mark 1382by making an exclamation mark
1226.Pq Dq \&! 1383.Pq Dq \&!
1227the first character of the character class. 1384the first character of the character class.
1228.Pp 1385.Pp
1229To include a 1386To include a
1230.Dq \&] 1387.Dq \&]
1231in a character class, make it the first character listed (after the 1388in a character class, make it the first character listed (after the
1232.Dq \&! , 1389.Dq \&! ,
1233if any). 1390if any).
1234To include a 1391To include a
1235.Dq - , 1392.Dq \(mi ,
1236make it the first or last character listed. 1393make it the first or last character listed.
1237.Ss Built-ins 1394.Ss Built-ins
1238This section lists the built-in commands which are built-in because they 1395This section lists the built-in commands which are built-in because they
1239need to perform some operation that can't be performed by a separate 1396need to perform some operation that can't be performed by a separate
1240process. 1397process.
1241In addition to these, there are several other commands that may 1398In addition to these, there are several other commands that may
1242be built in for efficiency (e.g. 1399be built in for efficiency (e.g.
1243.Xr printf 1 , 1400.Xr printf 1 ,
1244.Xr echo 1 , 1401.Xr echo 1 ,
1245.Xr test 1 , 1402.Xr test 1 ,
1246etc). 1403etc).
1247.Bl -tag -width 5n 1404.Bl -tag -width 5n
1248.It : [ Ar arg ... ] 1405.It : [ Ar arg ... ]
1249A null command that returns a 0 (true) exit value. 1406A null command that returns a 0 (true) exit value.
1250Any arguments are ignored. 1407Any arguments or redirects are evaluated, then ignored.
1251.It \&. file 1408.It \&. file
1252The dot command reads and executes the commands from the specified 1409The dot command reads and executes the commands from the specified
1253.Ar file 1410.Ar file
1254in the current shell environment. 1411in the current shell environment.
1255The file does not need to be executable and is looked up from the directories 1412The file does not need to be executable and is looked up from the directories
1256listed in the 1413listed in the
1257.Ev PATH 1414.Ev PATH
1258variable if it does not contain a directory separator 1415variable if its name does not contain a directory separator
1259.Pq Sq / . 1416.Pq Sq / .
1260The return command can be used for a premature return from the sourced file. 1417The return command can be used for a premature return from the sourced file.
1261.Pp 1418.Pp
1262The POSIX standard is unclear on how loop control keywords (break 1419The POSIX standard has been unclear on how loop control keywords (break
1263and continue) behave across a dot command boundary. 1420and continue) behave across a dot command boundary.
1264This implementation allows them to control loops surrounding the dot command, 1421This implementation allows them to control loops surrounding the dot command,
1265but obviously such behavior should not be relied on. 1422but obviously such behavior should not be relied on.
 1423It is now permitted by the standard, but not required.
1266.It alias Op Ar name Ns Op Ar "=string ..." 1424.It alias Op Ar name Ns Op Ar "=string ..."
1267If 1425If
1268.Ar name=string 1426.Ar name=string
1269is specified, the shell defines the alias 1427is specified, the shell defines the alias
1270.Ar name 1428.Ar name
1271with value 1429with value
1272.Ar string . 1430.Ar string .
1273If just 1431If just
1274.Ar name 1432.Ar name
1275is specified, the value of the alias 1433is specified, the value of the alias
1276.Ar name 1434.Ar name
1277is printed. 1435is printed.
1278With no arguments, the 1436With no arguments, the
1279.Ic alias 1437.Ic alias
1280built-in prints the 1438built-in prints the
1281names and values of all defined aliases (see 1439names and values of all defined aliases (see
1282.Ic unalias ) . 1440.Ic unalias ) .
1283.It bg [ Ar job ] ... 1441.It bg [ Ar job ] ...
1284Continue the specified jobs (or the current job if no 1442Continue the specified jobs (or the current job if no
1285jobs are given) in the background. 1443jobs are given) in the background.
1286.It command Oo Fl p Oc Oo Fl v Oc Oo Fl V Oc Ar command Oo Ar arg ... Oc 1444.It command Oo Fl p Oc Oo Fl v Oc Oo Fl V Oc Ar command Oo Ar arg ... Oc
1287Execute the specified command but ignore shell functions when searching 1445Execute the specified command but ignore shell functions when searching
1288for it. 1446for it.
1289(This is useful when you 1447(This is useful when you
1290have a shell function with the same name as a built-in command.) 1448have a shell function with the same name as a command.)
1291.Bl -tag -width 5n 1449.Bl -tag -width 5n
1292.It Fl p 1450.It Fl p
1293search for command using a 1451search for command using a
1294.Ev PATH 1452.Ev PATH
1295that guarantees to find all the standard utilities. 1453that guarantees to find all the standard utilities.
1296.It Fl V 1454.It Fl V
1297Do not execute the command but 1455Do not execute the command but
1298search for the command and print the resolution of the 1456search for the command and print the resolution of the
1299command search. 1457command search.
1300This is the same as the 1458This is the same as the
1301.Ic type 1459.Ic type
1302built-in. 1460built-in.
1303.It Fl v 1461.It Fl v
@@ -1387,40 +1545,76 @@ or @@ -1387,40 +1545,76 @@ or
1387.Dv FD_CLOEXEC ) , 1545.Dv FD_CLOEXEC ) ,
1388unless the descriptors they point to refer to the standard input, 1546unless the descriptors they point to refer to the standard input,
1389output, or error (file descriptors 0, 1, 2). 1547output, or error (file descriptors 0, 1, 2).
1390Traditionally Bourne-like shells 1548Traditionally Bourne-like shells
1391(except 1549(except
1392.Xr ksh 1 ) , 1550.Xr ksh 1 ) ,
1393made those file descriptors available to exec'ed processes. 1551made those file descriptors available to exec'ed processes.
1394.It exit Op Ar exitstatus 1552.It exit Op Ar exitstatus
1395Terminate the shell process. 1553Terminate the shell process.
1396If 1554If
1397.Ar exitstatus 1555.Ar exitstatus
1398is given it is used as the exit status of the shell; otherwise the 1556is given it is used as the exit status of the shell; otherwise the
1399exit status of the preceding command is used. 1557exit status of the preceding command is used.
1400.It export Ar name ... 1558.It export Oo Fl npx Oc Ar name ...
1401.It export Fl p 1559.It export Fl p Oo Fl x Oc
1402The specified names are exported so that they will appear in the 1560With no options,
 1561the specified names are exported so that they will appear in the
1403environment of subsequent commands. 1562environment of subsequent commands.
1404The only way to un-export a variable is to unset it. 1563With
 1564.Fl n
 1565the specified names are un-exported.
 1566Variables can also be un-exported using the unset builtin command.
 1567With
 1568.Fl x
 1569(exclude) the specified names are marked not to be exported,
 1570and any that had been exported, will be un-exported.
 1571Later attempts to export the variable will be refused.
 1572Note this does not prevent explicitly exporting a variable
 1573to a single command, script or function by preceding that
 1574command invocation by a variable assignment to that variable,
 1575provided the variable is not also readonly.
 1576That is
 1577.Dl export -x FOO ; # FOO will now not be exported by default
 1578.Dl FOO=some_value my_command
 1579still passes the value (FOO=some_value) to
 1580.Ic my_command
 1581through the environment.
 1582.Pp
1405The shell allows the value of a variable to be set at the 1583The shell allows the value of a variable to be set at the
1406same time it is exported by writing 1584same time it is exported by writing
1407.Pp 1585.Pp
1408.Dl export name=value 1586.Dl export name=value
1409.Pp 1587.Pp
1410With no arguments the export command lists the names of all exported variables. 1588With no arguments the export command lists the names of all exported variables,
 1589or if
 1590.Fl x
 1591was given, all variables marked not for export.
1411With the 1592With the
1412.Fl p 1593.Fl p
1413option specified the output will be formatted suitably for non-interactive use. 1594option specified the output will be formatted suitably for non-interactive use.
 1595.Pp
 1596The
 1597.Ic export
 1598built-in exits with status 0,
 1599unless an invalid option, or option combination, is given,
 1600or unless an attempt is made to export a variable which has
 1601been marked as unavailable for export,
 1602in which cases it exits with status 1.
 1603.Pp
 1604Note that there is no restriction upon exporting,
 1605or un-exporting, readonly variables.
 1606The no-export flag can be reset by unsetting the variable
 1607and creating it again \(en provided it is not also readonly.
1414.It fc Oo Fl e Ar editor Oc Oo Ar first Oo Ar last Oc Oc 1608.It fc Oo Fl e Ar editor Oc Oo Ar first Oo Ar last Oc Oc
1415.It fc Fl l Oo Fl nr Oc Oo Ar first Oo Ar last Oc Oc 1609.It fc Fl l Oo Fl nr Oc Oo Ar first Oo Ar last Oc Oc
1416.It fc Fl s Oo Ar old=new Oc Oo Ar first Oc 1610.It fc Fl s Oo Ar old=new Oc Oo Ar first Oc
1417The 1611The
1418.Ic fc 1612.Ic fc
1419built-in lists, or edits and re-executes, commands previously entered 1613built-in lists, or edits and re-executes, commands previously entered
1420to an interactive shell. 1614to an interactive shell.
1421.Bl -tag -width 5n 1615.Bl -tag -width 5n
1422.It Fl e No editor 1616.It Fl e No editor
1423Use the editor named by editor to edit the commands. 1617Use the editor named by editor to edit the commands.
1424The editor string is a command name, subject to search via the 1618The editor string is a command name, subject to search via the
1425.Ev PATH 1619.Ev PATH
1426variable. 1620variable.
@@ -1750,43 +1944,45 @@ If no arguments are present, the set com @@ -1750,43 +1944,45 @@ If no arguments are present, the set com
1750will clear all the positional parameters (equivalent to executing 1944will clear all the positional parameters (equivalent to executing
1751.Dq shift $# . ) 1945.Dq shift $# . )
1752.It setvar Ar variable Ar value 1946.It setvar Ar variable Ar value
1753Assigns value to variable. 1947Assigns value to variable.
1754(In general it is better to write 1948(In general it is better to write
1755variable=value rather than using 1949variable=value rather than using
1756.Ic setvar . 1950.Ic setvar .
1757.Ic setvar 1951.Ic setvar
1758is intended to be used in 1952is intended to be used in
1759functions that assign values to variables whose names are passed as 1953functions that assign values to variables whose names are passed as
1760parameters.) 1954parameters.)
1761.It shift Op Ar n 1955.It shift Op Ar n
1762Shift the positional parameters n times. 1956Shift the positional parameters n times.
1763A 1957If n is omitted, 1 is assumed.
 1958Each
1764.Ic shift 1959.Ic shift
1765sets the value of 1960sets the value of
1766.Va $1 1961.Va $1
1767to the value of 1962to the previous value of
1768.Va $2 , 1963.Va $2 ,
1769the value of 1964the value of
1770.Va $2 1965.Va $2
1771to the value of 1966to the previous value of
1772.Va $3 , 1967.Va $3 ,
1773and so on, decreasing 1968and so on, decreasing
1774the value of 1969the value of
1775.Va $# 1970.Va $#
1776by one. 1971by one.
1777If there are zero positional parameters, 1972The shift count must be less than or equal to the number of
1778.Ic shift 1973positional parameters (
1779does nothing. 1974.Dq $# )
 1975before the shift.
1780.It trap Oo Fl l Oc 1976.It trap Oo Fl l Oc
1781.It trap Oo Ar action Oc Ar signal ... 1977.It trap Oo Ar action Oc Ar signal ...
1782Cause the shell to parse and execute action when any of the specified 1978Cause the shell to parse and execute action when any of the specified
1783signals are received. 1979signals are received.
1784The signals are specified by signal number or as the name of the signal. 1980The signals are specified by signal number or as the name of the signal.
1785If 1981If
1786.Ar signal 1982.Ar signal
1787is 1983is
1788.Li 0 1984.Li 0
1789or its equivalent, EXIT, 1985or its equivalent, EXIT,
1790the action is executed when the shell exits. 1986the action is executed when the shell exits.
1791.Ar action 1987.Ar action
1792may be null, which cause the specified signals to be ignored. 1988may be null, which cause the specified signals to be ignored.
@@ -1820,27 +2016,29 @@ Examples: @@ -1820,27 +2016,29 @@ Examples:
1820.Pp 2016.Pp
1821List trapped signals and their corresponding action 2017List trapped signals and their corresponding action
1822.Pp 2018.Pp
1823.Dl trap -l 2019.Dl trap -l
1824.Pp 2020.Pp
1825Print a list of valid signals 2021Print a list of valid signals
1826.Pp 2022.Pp
1827.Dl trap '' INT QUIT tstp 30 2023.Dl trap '' INT QUIT tstp 30
1828.Pp 2024.Pp
1829Ignore signals INT QUIT TSTP USR1 2025Ignore signals INT QUIT TSTP USR1
1830.Pp 2026.Pp
1831.Dl trap date INT 2027.Dl trap date INT
1832.Pp 2028.Pp
1833Print date upon receiving signal INT 2029Run the
 2030.Dq date
 2031command (print the date) upon receiving signal INT
1834.It type Op Ar name ... 2032.It type Op Ar name ...
1835Interpret each name as a command and print the resolution of the command 2033Interpret each name as a command and print the resolution of the command
1836search. 2034search.
1837Possible resolutions are: 2035Possible resolutions are:
1838shell keyword, alias, shell built-in, 2036shell keyword, alias, shell built-in,
1839command, tracked alias and not found. 2037command, tracked alias and not found.
1840For aliases the alias expansion is 2038For aliases the alias expansion is
1841printed; for commands and tracked aliases the complete pathname of the 2039printed; for commands and tracked aliases the complete pathname of the
1842command is printed. 2040command is printed.
1843.It ulimit Oo Fl H \*(Ba Fl S Oc Oo Fl a \*(Ba Fl btfdscmlrpnv Oo Ar value Oc Oc 2041.It ulimit Oo Fl H \*(Ba Fl S Oc Oo Fl a \*(Ba Fl btfdscmlrpnv Oo Ar value Oc Oc
1844Inquire about or set the hard or soft limits on processes or set new 2042Inquire about or set the hard or soft limits on processes or set new
1845limits. 2043limits.
1846The choice between hard limit (which no process is allowed to 2044The choice between hard limit (which no process is allowed to
@@ -1909,35 +2107,74 @@ utility. @@ -1909,35 +2107,74 @@ utility.
1909.Pp 2107.Pp
1910.It umask Op Ar mask 2108.It umask Op Ar mask
1911Set the value of umask (see 2109Set the value of umask (see
1912.Xr umask 2 ) 2110.Xr umask 2 )
1913to the specified octal value. 2111to the specified octal value.
1914If the argument is omitted, the umask value is printed. 2112If the argument is omitted, the umask value is printed.
1915.It unalias Oo Fl a Oc Oo Ar name Oc 2113.It unalias Oo Fl a Oc Oo Ar name Oc
1916If 2114If
1917.Ar name 2115.Ar name
1918is specified, the shell removes that alias. 2116is specified, the shell removes that alias.
1919If 2117If
1920.Fl a 2118.Fl a
1921is specified, all aliases are removed. 2119is specified, all aliases are removed.
1922.It unset Ar name ... 2120.It unset Oo Fl efv Oc Ar name ...
1923The specified variables and functions are unset and unexported. 2121If
1924If a given name corresponds to both a variable and a function, both 2122.Fl v
1925the variable and the function are unset. 2123is specified, the specified variables are unset and unexported.
 2124Readonly variables cannot be unset.
 2125If
 2126.Fl f
 2127is specified, the specified functions are undefined.
 2128If
 2129.Fl e
 2130is given, the specified variables are unexported, but otherwise unchanged.
 2131.Pp
 2132If no flags are provided
 2133.Fl v
 2134is assumed.
 2135If
 2136.Fl f
 2137is given with one (or both) of
 2138.Fl v
 2139or
 2140.Fl e ,
 2141then the named variables will be unset, or unexported, and functions
 2142of the same names will be undefined.
 2143It makes no sense to give both
 2144.Fl v
 2145and
 2146.Fl e
 2147as unsetting a variable unexports it as well.
 2148However doing so is not an error, the last specified is used.
 2149The exit status is 0, unless an attempt was made to unset
 2150a readonly variable, in which case the exit status is 1.
 2151It is not an error to unset (or undefine) a variable (or function)
 2152that is not currently set (or defined.)
1926.It wait Op Ar job 2153.It wait Op Ar job
1927Wait for the specified job to complete and return the exit status of the 2154Wait for the specified job to complete and return the exit status of the
1928last process in the job. 2155last process in the job, or 127 if the job is not a current child of
 2156the shell.
1929If the argument is omitted, wait for all jobs to 2157If the argument is omitted, wait for all jobs to
1930complete and then return an exit status of zero. 2158complete and then return an exit status of zero.
 2159If the wait is interrupted by a signal,
 2160its exit status will be greater than 128.
 2161.Pp
 2162Once waited upon, by specific process number or job-id,
 2163or by a
 2164.Ic wait
 2165with no argumentss,
 2166knowledge of the child is removed from the system,
 2167and it cannot be waited upon again.
1931.El 2168.El
1932.Ss Command Line Editing 2169.Ss Command Line Editing
1933When 2170When
1934.Nm 2171.Nm
1935is being used interactively from a terminal, the current command 2172is being used interactively from a terminal, the current command
1936and the command history (see 2173and the command history (see
1937.Ic fc 2174.Ic fc
1938in the 2175in the
1939.Sx Built-ins 2176.Sx Built-ins
1940section) 2177section)
1941can be edited using emacs-mode or vi-mode command-line editing. 2178can be edited using emacs-mode or vi-mode command-line editing.
1942The command 2179The command
1943.Ql set -o emacs 2180.Ql set -o emacs
@@ -1974,98 +2211,110 @@ The @@ -1974,98 +2211,110 @@ The
1974mode uses commands similar to a subset available in 2211mode uses commands similar to a subset available in
1975the 2212the
1976.Xr emacs 1 2213.Xr emacs 1
1977editor. 2214editor.
1978With emacs-mode enabled, special keys can be used to modify the text 2215With emacs-mode enabled, special keys can be used to modify the text
1979in the buffer using the control key. 2216in the buffer using the control key.
1980.Pp 2217.Pp
1981.Nm 2218.Nm
1982uses the 2219uses the
1983.Xr editline 3 2220.Xr editline 3
1984library. 2221library.
1985.Sh ENVIRONMENT 2222.Sh ENVIRONMENT
1986.Bl -tag -width MAILCHECK 2223.Bl -tag -width MAILCHECK
 2224.It Ev CDPATH
 2225The search path used with the
 2226.Ic cd
 2227built-in.
 2228.It Ev HISTSIZE
 2229The number of lines in the history buffer for the shell.
1987.It Ev HOME 2230.It Ev HOME
1988Set automatically by 2231Set automatically by
1989.Xr login 1 2232.Xr login 1
1990from the user's login directory in the password file 2233from the user's login directory in the password file
1991.Pq Xr passwd 5 . 2234.Pq Xr passwd 5 .
1992This environment variable also functions as the default argument for the 2235This environment variable also functions as the default argument for the
1993.Ic cd 2236.Ic cd
1994built-in. 2237built-in.
1995.It Ev PATH 2238.It Ev IFS
1996The default search path for executables. 2239Input Field Separators.
 2240This is normally set to
 2241.Aq space ,
 2242.Aq tab ,
 2243and
 2244.Aq newline .
1997See the 2245See the
1998.Sx Path Search 2246.Sx White Space Splitting
1999section above. 2247section for more details.
2000.It Ev CDPATH 
2001The search path used with the 
2002.Ic cd 
2003built-in. 
2004.It Ev LINENO 
2005The current line number in the script or function. 
2006.It Ev LANG 2248.It Ev LANG
2007The string used to specify localization information that allows users 2249The string used to specify localization information that allows users
2008to work with different culture-specific and language conventions. 2250to work with different culture-specific and language conventions.
2009See 2251See
2010.Xr nls 7 . 2252.Xr nls 7 .
 2253.It Ev LINENO
 2254The current line number in the script or function.
2011.It Ev MAIL 2255.It Ev MAIL
2012The name of a mail file, that will be checked for the arrival of new mail. 2256The name of a mail file, that will be checked for the arrival of new mail.
2013Overridden by 2257Overridden by
2014.Ev MAILPATH . 2258.Ev MAILPATH .
2015.It Ev MAILCHECK 2259.It Ev MAILCHECK
2016The frequency in seconds that the shell checks for the arrival of mail 2260The frequency in seconds that the shell checks for the arrival of mail
2017in the files specified by the 2261in the files specified by the
2018.Ev MAILPATH 2262.Ev MAILPATH
2019or the 2263or the
2020.Ev MAIL 2264.Ev MAIL
2021file. 2265file.
2022If set to 0, the check will occur at each prompt. 2266If set to 0, the check will occur at each prompt.
2023.It Ev MAILPATH 2267.It Ev MAILPATH
2024A colon 2268A colon
2025.Dq \&: 2269.Dq \&:
2026separated list of file names, for the shell to check for incoming mail. 2270separated list of file names, for the shell to check for incoming mail.
2027This environment setting overrides the 2271This environment setting overrides the
2028.Ev MAIL 2272.Ev MAIL
2029setting. 2273setting.
2030There is a maximum of 10 mailboxes that can be monitored at once. 2274There is a maximum of 10 mailboxes that can be monitored at once.
 2275.It Ev PATH
 2276The default search path for executables.
 2277See the
 2278.Sx Path Search
 2279section above.
2031.It Ev PS1 2280.It Ev PS1
2032The primary prompt string, which defaults to 2281The primary prompt string, which defaults to
2033.Dq $ \ , 2282.Dq $ \ ,
2034unless you are the superuser, in which case it defaults to 2283unless you are the superuser, in which case it defaults to
2035.Dq # \ . 2284.Dq # \ .
2036.It Ev PS2 2285.It Ev PS2
2037The secondary prompt string, which defaults to 2286The secondary prompt string, which defaults to
2038.Dq \*[Gt] \ . 2287.Dq \*[Gt] \ .
2039.It Ev PS4 2288.It Ev PS4
2040Output before each line when execution trace (set -x) is enabled, 2289Output before each line when execution trace (set -x) is enabled,
2041defaults to 2290defaults to
2042.Dq + \ . 2291.Dq + \ .
2043.It Ev IFS 
2044Input Field Separators. 
2045This is normally set to 
2046.Aq space , 
2047.Aq tab , 
2048and 
2049.Aq newline . 
2050See the 
2051.Sx White Space Splitting 
2052section for more details. 
2053.It Ev TERM 2292.It Ev TERM
2054The default terminal setting for the shell. 2293The default terminal setting for the shell.
2055This is inherited by 2294This is inherited by
2056children of the shell, and is used in the history editing modes. 2295children of the shell, and is used in the history editing modes.
2057.It Ev HISTSIZE 2296.\" This is explicitly last, not in sort order - please leave!
2058The number of lines in the history buffer for the shell. 2297.It Ev NETBSD_SHELL
 2298Unlike the variables mentioned above,
 2299this variable is somewhat strange,
 2300in that it cannot be set,
 2301inherited from the environment,
 2302modified, or exported from the shell.
 2303If set, it indicates that the shell is the
 2304.Ic sh
 2305defined by this manual page, and gives its version information.
 2306It behaves like any other variable that has the read-only
 2307and un-exportable attributes set.
2059.El 2308.El
2060.Sh FILES 2309.Sh FILES
2061.Bl -item 2310.Bl -item
2062.It 2311.It
2063.Pa $HOME/.profile 2312.Pa $HOME/.profile
2064.It 2313.It
2065.Pa /etc/profile 2314.Pa /etc/profile
2066.El 2315.El
2067.Sh EXIT STATUS 2316.Sh EXIT STATUS
2068Errors that are detected by the shell, such as a syntax error, will cause the 2317Errors that are detected by the shell, such as a syntax error, will cause the
2069shell to exit with a non-zero exit status. 2318shell to exit with a non-zero exit status.
2070If the shell is not an 2319If the shell is not an
2071interactive shell, the execution of the shell file will be aborted. 2320interactive shell, the execution of the shell file will be aborted.
@@ -2095,13 +2344,15 @@ A @@ -2095,13 +2344,15 @@ A
2095command appeared in 2344command appeared in
2096.At v1 . 2345.At v1 .
2097It was, however, unmaintainable so we wrote this one. 2346It was, however, unmaintainable so we wrote this one.
2098.Sh BUGS 2347.Sh BUGS
2099Setuid shell scripts should be avoided at all costs, as they are a 2348Setuid shell scripts should be avoided at all costs, as they are a
2100significant security risk. 2349significant security risk.
2101.Pp 2350.Pp
2102PS1, PS2, and PS4 should be subject to parameter expansion before 2351PS1, PS2, and PS4 should be subject to parameter expansion before
2103being displayed. 2352being displayed.
2104.Pp 2353.Pp
2105The characters generated by filename completion should probably be quoted 2354The characters generated by filename completion should probably be quoted
2106to ensure that the filename is still valid after the input line has been 2355to ensure that the filename is still valid after the input line has been
2107processed. 2356processed.
 2357.Pp
 2358Many, many, more.