diff options
Diffstat (limited to 'bin/cash')
-rw-r--r-- | bin/cash/cash.1 | 300 |
1 files changed, 299 insertions, 1 deletions
diff --git a/bin/cash/cash.1 b/bin/cash/cash.1 index 94031bb9..b0cbdee0 100644 --- a/bin/cash/cash.1 +++ b/bin/cash/cash.1 @@ -31,13 +31,15 @@ .\" .\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95 .\" $FreeBSD: releng/12.0/bin/sh/sh.1 336483 2018-07-19 13:09:29Z 0mp $ -.\" +. .Dd January 10, 2019 .Dt CASH 1 .Os +. .Sh NAME .Nm cash .Nd the Causal Agency shell +. .Sh SYNOPSIS .Nm .Op Fl /+abCEefhIimnPpTuVvx @@ -46,6 +48,7 @@ .Ar script .Op Ar arg ... .Oc +. .Nm .Op Fl /+abCEefhIimnPpTuVvx .Op Fl /+o Ar longname @@ -54,11 +57,13 @@ .Ar name .Op Ar arg ... .Oc +. .Nm .Op Fl /+abCEefhIimnPpTuVvx .Op Fl /+o Ar longname .Fl s .Op Ar arg ... +. .Sh DESCRIPTION The .Nm @@ -73,6 +78,7 @@ designated by POSIX, plus a few Berkeley extensions. This man page is not intended to be a tutorial nor a complete specification of the shell. +. .Ss Overview The shell is a command that reads lines from either a file or the terminal, interprets them, and @@ -93,6 +99,7 @@ use (shell scripts). That is, commands can be typed directly to the running shell or can be put into a file, which can be executed directly by the shell. +. .Ss Invocation .\" .\" XXX This next sentence is incredibly confusing. @@ -139,8 +146,10 @@ in the home directory, substituting for .Pa .cashrc the filename desired: +. .Pp .Dl "ENV=$HOME/.cashrc; export ENV" +. .Pp The first non-option argument specified on the command line will be treated as the @@ -151,6 +160,7 @@ of the shell etc.). Otherwise, the shell reads commands from its standard input. +. .Pp Unlike older versions of .Xr sh 1 @@ -162,6 +172,7 @@ closes a well-known, and sometimes easily exploitable security hole related to poorly thought out .Ev ENV scripts. +. .Ss Argument List Processing All of the single letter options to .Nm @@ -202,16 +213,20 @@ and .Fl c options do not have long names. They take arguments and are described after the single letter options. +. .Bl -tag -width indent .It Fl a Li allexport Flag variables for export when assignments are made to them. +. .It Fl b Li notify Enable asynchronous notification of background job completion. (UNIMPLEMENTED) +. .It Fl C Li noclobber Do not overwrite existing files with .Ql > . +. .It Fl E Li emacs Enable the built-in .Xr emacs 1 @@ -219,6 +234,7 @@ command line editor (disables the .Fl V option if it has been set; set automatically when interactive on terminals). +. .It Fl e Li errexit Exit immediately if any untested command fails in non-interactive mode. The exit status of a command is considered to be @@ -238,22 +254,28 @@ keyword. If a shell function is executed and its exit status is explicitly tested, all commands of the function are considered to be tested as well. +. .Pp It is recommended to check for failures explicitly instead of relying on .Fl e because it tends to behave in unexpected ways, particularly in larger scripts. +. .It Fl f Li noglob Disable pathname expansion. +. .It Fl h Li trackall A do-nothing option for POSIX compliance. +. .It Fl I Li ignoreeof Ignore .Dv EOF Ap s from input when in interactive mode. +. .It Fl i Li interactive Force the shell to behave interactively. +. .It Fl m Li monitor Turn on job control (set automatically when interactive). A new process group is created for each pipeline (called a job). @@ -262,11 +284,13 @@ in the background. In a non-interactive shell, this option can be set even if no terminal is available and is useful to place processes in separate process groups. +. .It Fl n Li noexec If not interactive, read commands but do not execute them. This is useful for checking the syntax of shell scripts. +. .It Fl P Li physical Change the default for the .Ic cd @@ -278,6 +302,7 @@ commands from to .Fl P (physical directory layout). +. .It Fl p Li privileged Turn on privileged mode. This mode is enabled on startup @@ -294,6 +319,7 @@ after is sourced, and the contents of the .Ev ENV variable are ignored. +. .It Fl s Li stdin Read commands from standard input (set automatically if no file arguments are present). @@ -302,6 +328,7 @@ no effect when set after the shell has already started running (i.e., when set with the .Ic set command). +. .It Fl T Li trapsasync When waiting for a child, execute traps immediately. If this option is not set, @@ -316,6 +343,7 @@ like this: .Bd -literal -offset indent cash -T -c "trap 'exit 1' 2 ; some-blocking-program" .Ed +. .It Fl u Li nounset Write a message to standard error when attempting to expand a variable, a positional parameter or @@ -323,16 +351,19 @@ the special parameter .Va \&! that is not set, and if the shell is not interactive, exit immediately. +. .It Fl V Li vi Enable the built-in .Xr vi 1 command line editor (disables .Fl E if it has been set). +. .It Fl v Li verbose The shell writes its input to standard error as it is read. Useful for debugging. +. .It Fl x Li xtrace Write each command (preceded by the value of the @@ -340,10 +371,12 @@ Write each command variable subjected to parameter expansion and arithmetic expansion) to standard error before it is executed. Useful for debugging. +. .It Li nolog Another do-nothing option for POSIX compliance. It only has a long name. .El +. .Pp The .Fl c @@ -352,6 +385,7 @@ option causes the commands to be read from the operand instead of from the standard input. Keep in mind that this option only accepts a single string as its argument, hence multi-word strings must be quoted. +. .Pp The .Fl /+o @@ -366,6 +400,7 @@ command line editor: set -E set -o emacs .Ed +. .Pp If used without an argument, the .Fl o @@ -374,6 +409,7 @@ If .Cm +o is used without an argument, the current option settings are output in a format suitable for re-input into the shell. +. .Ss Lexical Structure The shell reads input in terms of lines from a file and breaks it up into words at whitespace (blanks and tabs), and at @@ -384,18 +420,21 @@ which are special to the shell. There are two types of operators: control operators and redirection operators (their meaning is discussed later). The following is a list of valid operators: +. .Bl -tag -width indent .It Control operators: .Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact .It Li & Ta Li && Ta Li \&( Ta Li \&) Ta Li \en .It Li ;; Ta Li ;& Ta Li \&; Ta Li \&| Ta Li || .El +. .It Redirection operators: .Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact .It Li < Ta Li > Ta Li << Ta Li >> Ta Li <> .It Li <& Ta Li >& Ta Li <<- Ta Li >| Ta \& .El .El +. .Pp The character .Ql # @@ -403,23 +442,28 @@ introduces a comment if used at the beginning of a word. The word starting with .Ql # and the rest of the line are ignored. +. .Pp ASCII .Dv NUL characters (character code 0) are not allowed in shell input. +. .Ss Quoting Quoting is used to remove the special meaning of certain characters or words to the shell, such as operators, whitespace, keywords, or alias names. +. .Pp There are four types of quoting: matched single quotes, dollar-single quotes, matched double quotes, and backslash. +. .Bl -tag -width indent .It Single Quotes Enclosing characters in single quotes preserves the literal meaning of all the characters (except single quotes, making it impossible to put single-quotes in a single-quoted string). +. .It Dollar-Single Quotes Enclosing characters between .Li $' @@ -428,6 +472,7 @@ and preserves the literal meaning of all characters except backslashes and single quotes. A backslash introduces a C-style escape sequence: +. .Bl -tag -width xUnnnnnnnn .It \ea Alert (ring the terminal bell) @@ -476,16 +521,20 @@ The Unicode code point .Ar nnnnnnnn (eight hexadecimal digits) .El +. .Pp The sequences for Unicode code points are currently only useful with UTF-8 locales. They reject code point 0 and UTF-16 surrogates. +. .Pp If an escape sequence would produce a byte with value 0, that byte and the rest of the string until the matching single-quote are ignored. +. .Pp Any other string starting with a backslash is an error. +. .It Double Quotes Enclosing characters within double quotes preserves the literal meaning of all characters except dollar sign @@ -497,16 +546,19 @@ and backslash The backslash inside double quotes is historically weird. It remains literal unless it precedes the following characters, which it serves to quote: +. .Pp .Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact .It Li $ Ta Li ` Ta Li \&" Ta Li \e Ta Li \en .El +. .It Backslash A backslash preserves the literal meaning of the following character, with the exception of the newline character .Pq Ql \en . A backslash preceding a newline is treated as a line continuation. .El +. .Ss Keywords Keywords or reserved words are words that have special meaning to the shell and are recognized at the beginning of a line and @@ -517,6 +569,7 @@ The following are keywords: .It Ic done Ta Ic elif Ta Ic else Ta Ic esac Ta Ic fi .It Ic for Ta Ic if Ta Ic then Ta Ic until Ta Ic while .El +. .Ss Aliases An alias is a name and corresponding value set using the .Ic alias @@ -536,6 +589,7 @@ then the input would become .Pp .Dl "ls -F foobar" +. .Pp Aliases are also recognized after an alias whose value ends with a space or tab. @@ -550,6 +604,7 @@ then the input would become .Pp .Dl "nohup ls -F foobar" +. .Pp Aliases provide a convenient way for naive users to create shorthands for commands without having to learn how @@ -558,6 +613,7 @@ Using aliases in scripts is discouraged because the command that defines them must be executed before the code that uses them is parsed. This is fragile and not portable. +. .Pp An alias name may be escaped in a command line, so that it is not replaced by its alias value, by using quoting characters within or @@ -568,6 +624,7 @@ normal program with the same name. See the .Sx Quoting subsection. +. .Ss Commands The shell interprets the words it reads according to a language, the specification of which is outside the scope @@ -580,9 +637,11 @@ is not a keyword, then the shell has recognized a simple command. Otherwise, a complex command or some other special construct may have been recognized. +. .Ss Simple Commands If a simple command has been recognized, the shell performs the following actions: +. .Bl -enum .It Leading words of the form @@ -593,6 +652,7 @@ the simple command Redirection operators and their arguments (as described below) are stripped off and saved for processing. +. .It The remaining words are expanded as described in the section called @@ -605,10 +665,12 @@ If no command name resulted, then the .Dq Li name=value variable assignments recognized in 1) affect the current shell. +. .It Redirections are performed as described in the next section. .El +. .Ss Redirections Redirections are used to change where a command reads its input or sends its output. @@ -618,6 +680,7 @@ The overall format used for redirection is: .Pp .D1 Oo Ar n Oc Ar redir-op file +. .Pp The .Ar redir-op @@ -627,48 +690,58 @@ The following gives some examples of how these operators can be used. Note that stdin and stdout are commonly used abbreviations for standard input and standard output respectively. +. .Bl -tag -width "1234567890XX" -offset indent .It Oo Ar n Oc Ns Li > Ar file redirect stdout (or file descriptor .Ar n ) to .Ar file +. .It Oo Ar n Oc Ns Li >| Ar file same as above, but override the .Fl C option +. .It Oo Ar n Oc Ns Li >> Ar file append stdout (or file descriptor .Ar n ) to .Ar file +. .It Oo Ar n Oc Ns Li < Ar file redirect stdin (or file descriptor .Ar n ) from .Ar file +. .It Oo Ar n Oc Ns Li <> Ar file redirect stdin (or file descriptor .Ar n ) to and from .Ar file +. .It Oo Ar n1 Oc Ns Li <& Ns Ar n2 duplicate stdin (or file descriptor .Ar n1 ) from file descriptor .Ar n2 +. .It Oo Ar n Oc Ns Li <&- close stdin (or file descriptor .Ar n ) +. .It Oo Ar n1 Oc Ns Li >& Ns Ar n2 duplicate stdout (or file descriptor .Ar n1 ) to file descriptor .Ar n2 +. .It Oo Ar n Oc Ns Li >&- close stdout (or file descriptor .Ar n ) .El +. .Pp The following redirection is often called a .Dq here-document . @@ -678,6 +751,7 @@ The following redirection is often called a .Ar ... .Ar delimiter .Ed +. .Pp All the text on successive lines up to the delimiter is saved away and made available to the command on standard @@ -700,11 +774,13 @@ then leading tabs in the .Ar here-doc-text are stripped. +. .Ss Search and Execution There are three types of commands: shell functions, built-in commands, and normal programs. The command is searched for (by name) in that order. The three types of commands are all executed in a different way. +. .Pp When a shell function is executed, all of the shell positional parameters (except @@ -719,6 +795,7 @@ Then the command given in the function definition is executed. The positional parameters are restored to their original values when the command completes. This all occurs within the current shell. +. .Pp Shell built-in commands are executed internally to the shell, without spawning a new process. @@ -729,6 +806,7 @@ operand errors cause a script to be aborted. Special builtins cannot be overridden with a function. Both regular and special builtins can affect the shell in ways normal programs cannot. +. .Pp Otherwise, if the command name does not match a function or built-in command, the command is searched for as a normal @@ -748,12 +826,14 @@ but appears to be a text file, the shell will run a new instance of .Nm to interpret it. +. .Pp Note that previous versions of this document and the source code itself misleadingly and sporadically refer to a shell script without a magic number as a .Dq "shell procedure" . +. .Ss Path Search When locating a command, the shell first looks to see if it has a shell function by that name. @@ -761,10 +841,12 @@ Then it looks for a built-in command by that name. If a built-in command is not found, one of two things happen: +. .Bl -enum .It Command names containing a slash are simply executed without performing any searches. +. .It The shell searches each entry in the .Va PATH @@ -780,6 +862,7 @@ The current directory may be indicated implicitly by an empty directory name, or explicitly by a single period. .El +. .Ss Command Exit Status Each command has an exit status that can influence the behavior of other shell commands. @@ -790,19 +873,23 @@ The man page for each command should indicate the various exit codes and what they mean. Additionally, the built-in commands return exit codes, as does an executed shell function. +. .Pp If a command is terminated by a signal, its exit status is greater than 128. The signal name can be found by passing the exit status to .Li kill -l . +. .Pp If there is no command word, the exit status is the exit status of the last command substitution executed, or zero if the command does not contain any command substitutions. +. .Ss Complex Commands Complex commands are combinations of simple commands with control operators or keywords, together creating a larger complex command. More generally, a command is one of the following: +. .Bl -item -offset indent .It simple command @@ -815,10 +902,12 @@ compound command .It function definition .El +. .Pp Unless otherwise stated, the exit status of a command is that of the last simple command executed by the command, or zero if no simple command was executed. +. .Ss Pipelines A pipeline is a sequence of one or more commands separated by the control operator @@ -828,10 +917,12 @@ the last command is connected to the standard input of the next command. The standard output of the last command is inherited from the shell, as usual. +. .Pp The format for a pipeline is: .Pp .D1 Oo Li \&! Oc Ar command1 Op Li \&| Ar command2 ... +. .Pp The standard output of .Ar command1 @@ -841,6 +932,7 @@ The standard input, standard output, or both of a command is considered to be assigned by the pipeline before any redirection specified by redirection operators that are part of the command. +. .Pp Note that unlike some other shells, .Nm @@ -848,9 +940,11 @@ executes each process in a pipeline with more than one command in a subshell environment and as a child of the .Nm process. +. .Pp If the pipeline is not in the background (discussed later), the shell waits for all commands to complete. +. .Pp If the keyword .Ic !\& @@ -863,6 +957,7 @@ That is, if the last command returns zero, the exit status is 1; if the last command returns greater than zero, the exit status is zero. +. .Pp Because pipeline assignment of standard input or standard output or both takes place before redirection, it can be @@ -870,11 +965,13 @@ modified by redirection. For example: .Pp .Dl "command1 2>&1 | command2" +. .Pp sends both the standard output and standard error of .Ar command1 to the standard input of .Ar command2 . +. .Pp A .Ql \&; @@ -886,6 +983,7 @@ to be executed sequentially; an .Ql & causes asynchronous execution of the preceding AND-OR-list. +. .Ss Background Commands (&) If a command is terminated by the control operator ampersand .Pq Ql & , @@ -894,16 +992,20 @@ the shell executes the command in a subshell environment (see below) and asynchronously; the shell does not wait for the command to finish before executing the next command. +. .Pp The format for running a command in background is: .Pp .D1 Ar command1 Li & Op Ar command2 Li & Ar ... +. .Pp If the shell is not interactive, the standard input of an asynchronous command is set to .Pa /dev/null . +. .Pp The exit status is zero. +. .Ss Lists (Generally Speaking) A list is a sequence of zero or more commands separated by newlines, semicolons, or ampersands, @@ -914,6 +1016,7 @@ If command is followed by an ampersand, the shell starts the command and immediately proceeds onto the next command; otherwise it waits for the command to terminate before proceeding to the next one. +. .Ss Short-Circuit List Operators .Dq Li && and @@ -929,6 +1032,7 @@ status of the first command is nonzero. and .Dq Li || both have the same priority. +. .Ss Flow-Control Constructs (if, while, for, case) The syntax of the .Ic if @@ -941,6 +1045,7 @@ command is: .Op Ic else Ar list .Ic fi .Ed +. .Pp The exit status is that of selected .Ic then @@ -948,6 +1053,7 @@ or .Ic else list, or zero if no list was selected. +. .Pp The syntax of the .Ic while @@ -957,6 +1063,7 @@ command is: .Ic do Ar list .Ic done .Ed +. .Pp The two lists are executed repeatedly while the exit status of the first list is zero. @@ -968,9 +1075,11 @@ in place of .Ic while , which causes it to repeat until the exit status of the first list is zero. +. .Pp The exit status is that of the last execution of the second list, or zero if it was never executed. +. .Pp The syntax of the .Ic for @@ -980,6 +1089,7 @@ command is: .Ic do Ar list .Ic done .Ed +. .Pp If .Ic in @@ -996,6 +1106,7 @@ commands may be replaced with .Ql { and .Ql } . +. .Pp The syntax of the .Ic break @@ -1004,6 +1115,7 @@ and commands is: .D1 Ic break Op Ar num .D1 Ic continue Op Ar num +. .Pp The .Ic break @@ -1018,6 +1130,7 @@ The .Ic continue command continues with the next iteration of the innermost loop. These are implemented as special built-in commands. +. .Pp The syntax of the .Ic case @@ -1028,6 +1141,7 @@ command is: .Ar ... .Ic esac .Ed +. .Pp The pattern can actually be one or more patterns (see @@ -1052,6 +1166,7 @@ continuing until a list terminated with or the end of the .Ic case command. +. .Ss Grouping Commands Together Commands may be grouped by writing either .Pp @@ -1065,6 +1180,7 @@ or .Bd -literal -offset -ident .No { Ar list ; } .Ed +. .Pp The first form executes the commands in a subshell environment. A subshell environment has its own copy of: @@ -1094,18 +1210,22 @@ Shell functions. .It Shell aliases. .El +. .Pp These are copied from the parent shell environment, except that trapped (but not ignored) signals are reset to the default action and known jobs are cleared. Any changes do not affect the parent shell environment. +. .Pp A subshell environment may be implemented as a child process or differently. If job control is enabled in an interactive shell, commands grouped in parentheses can be suspended and continued as a unit. +. .Pp For compatibility with other shells, two open parentheses in sequence should be separated by whitespace. +. .Pp The second form never forks another shell, so it is slightly more efficient. @@ -1114,10 +1234,12 @@ redirect their output as though they were one program: .Bd -literal -offset indent { echo -n "hello"; echo " world"; } > greeting .Ed +. .Ss Functions The syntax of a function definition is .Pp .D1 Ar name Li \&( \&) Ar command +. .Pp A function definition is an executable statement; when executed it installs a function named @@ -1131,6 +1253,7 @@ enclosed between .Ql { and .Ql } . +. .Pp Variables may be declared to be local to a function by using the @@ -1140,12 +1263,14 @@ This should appear as the first statement of a function, and the syntax is: .Pp .D1 Ic local Oo Ar variable ... Oc Op Fl +. .Pp The .Ic local command is implemented as a built-in command. The exit status is zero unless the command is not in a function or a variable name is invalid. +. .Pp When a variable is made local, it inherits the initial value and exported and readonly flags from the variable @@ -1169,6 +1294,7 @@ declared inside .Em f , not to the global variable named .Va x . +. .Pp The only special parameter that can be made local is .Ql - . @@ -1182,12 +1308,14 @@ changed via the command inside the function to be restored to their original values when the function returns. +. .Pp The syntax of the .Ic return command is .Pp .D1 Ic return Op Ar exitstatus +. .Pp It terminates the current executional scope, returning from the closest nested function or sourced script; @@ -1196,6 +1324,7 @@ it exits the shell instance. The .Ic return command is implemented as a special built-in command. +. .Ss Variables and Parameters The shell maintains a set of parameters. A parameter @@ -1210,14 +1339,17 @@ variables. New variables can be set using the form .Pp .D1 Ar name Ns = Ns Ar value +. .Pp A parameter can also be denoted by a number or a special character as explained below. +. .Pp Assignments are expanded differently from other words: tilde expansion is also performed after the equals sign and after any colon and usernames are also terminated by colons, and field splitting and pathname expansion are not performed. +. .Pp This special expansion applies not only to assignments that form a simple command by themselves or precede a command word, @@ -1232,6 +1364,7 @@ For this, the builtin's name must be literal and may optionally be preceded by one or more literal instances of .Ic command without options. +. .Ss Positional Parameters A positional parameter is a parameter denoted by a number greater than zero. The shell sets these initially to the values of its command line @@ -1239,11 +1372,13 @@ arguments that follow the name of the shell script. The .Ic set built-in command can also be used to set or reset them. +. .Ss Special Parameters Special parameters are parameters denoted by a single special character or the digit zero. They are shown in the following list, exactly as they would appear in input typed by the user or in the source of a shell script. +. .Bl -hang .It Li $* Expands to the positional parameters, starting from one. @@ -1256,6 +1391,7 @@ variable, or by a space if .Va IFS is unset. +. .It Li $@ Expands to the positional parameters, starting from one. When @@ -1283,10 +1419,13 @@ the two arguments: .Bd -literal -offset indent "abc" "def ghi" .Ed +. .It Li $# Expands to the number of positional parameters. +. .It Li $? Expands to the exit status of the most recent pipeline. +. .It Li $- (hyphen) Expands to the current option flags (the single-letter option names concatenated into a string) as specified on @@ -1294,12 +1433,14 @@ invocation, by the .Ic set built-in command, or implicitly by the shell. +. .It Li $$ Expands to the process ID of the invoked shell. A subshell retains the same value of .Va $ as its parent. +. .It Li $! Expands to the process ID of the most recent background command executed from the current shell. @@ -1310,6 +1451,7 @@ If this parameter is referenced, the shell will remember the process ID and its exit status until the .Ic wait built-in command reports completion of the process. +. .It Li $0 (zero) Expands to the name of the shell script if passed on the command line, the @@ -1318,31 +1460,38 @@ operand if given (with .Fl c ) or otherwise argument 0 passed to the shell. .El +. .Ss Special Variables The following variables are set by the shell or have special meaning to it: +. .Bl -tag -width ".Va HISTSIZE" .It Va CDPATH The search path used with the .Ic cd built-in. +. .It Va EDITOR The fallback editor used with the .Ic fc built-in. If not set, the default editor is .Xr ed 1 . +. .It Va FCEDIT The default editor used with the .Ic fc built-in. +. .It Va HISTSIZE The number of previous commands that are accessible. +. .It Va HOME The user's home directory, used in tilde expansion and as a default directory for the .Ic cd built-in. +. .It Va IFS Input Field Separators. This is initialized at startup to @@ -1357,13 +1506,16 @@ is unset, but not if it is set to the empty string. See the .Sx White Space Splitting section for more details. +. .It Va LINENO The current line number in the script or function. +. .It Va MAIL The name of a mail file, that will be checked for the arrival of new mail. Overridden by .Va MAILPATH . +. .It Va MAILPATH A colon .Pq Ql \&: @@ -1373,15 +1525,18 @@ This variable overrides the .Va MAIL setting. There is a maximum of 10 mailboxes that can be monitored at once. +. .It Va OPTIND The index of the next argument to be processed by .Ic getopts . This is initialized to 1 at startup. +. .It Va PATH The default search path for executables. See the .Sx Path Search section for details. +. .It Va PPID The parent process ID of the invoked shell. This is set at startup @@ -1389,6 +1544,7 @@ unless this variable is in the environment. A later change of parent process ID is not reflected. A subshell retains the same value of .Va PPID . +. .It Va PS1 The primary prompt string, which defaults to .Dq Li "$ " , @@ -1415,34 +1571,40 @@ for superusers. .It Li \e\e A literal backslash. .El +. .It Va PS2 The secondary prompt string, which defaults to .Dq Li "> " . .Va PS2 may include any of the formatting sequences from .Va PS1 . +. .It Va PS4 The prefix for the trace output (if .Fl x is active). The default is .Dq Li "+ " . +. .It Va RPS1 The primary right prompt string. .Va RPS1 may include any of the formatting sequences from .Va PS1 . +. .It Va RPS2 The secondary right prompt string. .Va RPS2 may include any of the formatting sequences from .Va PS1 . .El +. .Ss Word Expansions This clause describes the various expansions that are performed on words. Not all expansions are performed on every word, as explained later. +. .Pp Tilde expansions, parameter expansions, command substitutions, arithmetic expansions, and quote removals that occur within @@ -1455,6 +1617,7 @@ the expansion of the special parameter .Va @ within double-quotes, as was described above. +. .Pp The order of word expansion is: .Bl -enum @@ -1473,11 +1636,13 @@ option is in effect). .It Quote Removal. .El +. .Pp The .Ql $ character is used to introduce parameter expansion, command substitution, or arithmetic expansion. +. .Ss Tilde Expansion (substituting a user's home directory) A word beginning with an unquoted tilde character .Pq Ql ~ @@ -1493,6 +1658,7 @@ username is missing (as in the tilde is replaced with the value of the .Va HOME variable (the current user's home directory). +. .Ss Parameter Expansion The format for parameter expansion is as follows: .Pp @@ -1521,6 +1687,7 @@ as an extension there may be unquoted parts .Ql } within such parts are also not examined in determining the matching .Ql } . +. .Pp The simplest form for parameter expansion is: .Pp @@ -1529,6 +1696,7 @@ The simplest form for parameter expansion is: The value, if any, of .Ar parameter is substituted. +. .Pp The parameter name or symbol can be enclosed in braces, which are optional except for positional parameters with more than one digit or @@ -1544,9 +1712,11 @@ expansion, with the exception of the special parameter Pathname expansion is not performed on the results of the expansion. .El +. .Pp In addition, a parameter expansion can be modified by using one of the following formats. +. .Bl -tag -width indent .It Li ${ Ns Ar parameter Ns Li :- Ns Ar word Ns Li } Use Default Values. @@ -1557,6 +1727,7 @@ is unset or null, the expansion of is substituted; otherwise, the value of .Ar parameter is substituted. +. .It Li ${ Ns Ar parameter Ns Li := Ns Ar word Ns Li } Assign Default Values. If @@ -1575,6 +1746,7 @@ does not prevent field splitting or pathname expansion. Only variables, not positional parameters or special parameters, can be assigned in this way. +. .It Li ${ Ns Ar parameter Ns Li :? Ns Oo Ar word Oc Ns Li } Indicate Error if Null or Unset. If @@ -1591,6 +1763,7 @@ Otherwise, the value of is substituted. An interactive shell need not exit. +. .It Li ${ Ns Ar parameter Ns Li :+ Ns Ar word Ns Li } Use Alternate Value. If @@ -1600,10 +1773,12 @@ otherwise, the expansion of .Ar word is substituted. .El +. .Pp In the parameter expansions shown previously, use of the colon in the format results in a test for a parameter that is unset or null; omission of the colon results in a test for a parameter that is only unset. +. .Pp The .Ar word @@ -1619,6 +1794,7 @@ The length in characters of the value of .Ar parameter . .El +. .Pp The following four varieties of parameter expansion provide for substring processing. @@ -1635,6 +1811,7 @@ the result of the expansion is unspecified. Enclosing the full parameter expansion string in double-quotes does not cause the following four varieties of pattern characters to be quoted, whereas quoting characters within the braces has this effect. +. .Bl -tag -width indent .It Li ${ Ns Ar parameter Ns Li % Ns Ar word Ns Li } Remove Smallest Suffix Pattern. @@ -1646,6 +1823,7 @@ parameter expansion then results in .Ar parameter , with the smallest portion of the suffix matched by the pattern deleted. +. .It Li ${ Ns Ar parameter Ns Li %% Ns Ar word Ns Li } Remove Largest Suffix Pattern. The @@ -1656,6 +1834,7 @@ parameter expansion then results in .Ar parameter , with the largest portion of the suffix matched by the pattern deleted. +. .It Li ${ Ns Ar parameter Ns Li # Ns Ar word Ns Li } Remove Smallest Prefix Pattern. The @@ -1666,6 +1845,7 @@ parameter expansion then results in .Ar parameter , with the smallest portion of the prefix matched by the pattern deleted. +. .It Li ${ Ns Ar parameter Ns Li ## Ns Ar word Ns Li } Remove Largest Prefix Pattern. The @@ -1677,6 +1857,7 @@ parameter expansion then results in with the largest portion of the prefix matched by the pattern deleted. .El +. .Ss Command Substitution Command substitution allows the output of a command to be substituted in place of the command name itself. @@ -1688,6 +1869,7 @@ the command is enclosed as follows: or the backquoted version: .Pp .D1 Li ` Ns Ar command Ns Li ` +. .Pp The shell expands the command substitution by executing command and replacing the command substitution @@ -1709,6 +1891,7 @@ and .Ic times returns information about the same process if they are the only command in a command substitution. +. .Pp If a command substitution of the .Li $( @@ -1719,12 +1902,14 @@ and .Li (\& must be separated by whitespace to avoid ambiguity with arithmetic expansion. +. .Ss Arithmetic Expansion Arithmetic expansion provides a mechanism for evaluating an arithmetic expression and substituting its value. The format for arithmetic expansion is as follows: .Pp .D1 Li $(( Ns Ar expression Ns Li )) +. .Pp The .Ar expression @@ -1737,39 +1922,50 @@ for parameter expansion, command substitution, arithmetic expansion and quote removal. +. .Pp The allowed expressions are a subset of C expressions, summarized below. +. .Bl -tag -width "Variables" -offset indent .It Values All values are of type .Ft intmax_t . +. .It Constants Decimal, octal (starting with .Li 0 ) and hexadecimal (starting with .Li 0x ) integer constants. +. .It Variables Shell variables can be read and written and contain integer constants. +. .It Unary operators .Li "! ~ + -" +. .It Binary operators .Li "* / % + - << >> < <= > >= == != & ^ | && ||"\& +. .It Assignment operators .Li "= += -= *= /= %= <<= >>= &= ^= |=" +. .It Conditional operator .Li "? :"\& .El +. .Pp The result of the expression is substituted in decimal. +. .Ss White Space Splitting (Field Splitting) In certain contexts, after parameter expansion, command substitution, and arithmetic expansion the shell scans the results of expansions and substitutions that did not occur in double-quotes for field splitting and multiple fields can result. +. .Pp Characters in .Va IFS @@ -1782,10 +1978,12 @@ and .Pc are treated differently from other characters in .Va IFS . +. .Pp Whitespace in .Va IFS at the beginning or end of a word is discarded. +. .Pp Subsequently, a field is delimited by either .Bl -enum @@ -1799,10 +1997,12 @@ surrounding it, or one or more whitespace characters in .Va IFS . .El +. .Pp If a word ends with a non-whitespace character in .Va IFS , there is no empty field after this character. +. .Pp If no field is delimited, the word is discarded. In particular, if a word consists solely of an unquoted substitution @@ -1810,6 +2010,7 @@ and the result of the substitution is null, it is removed by field splitting even if .Va IFS is null. +. .Ss Pathname Expansion (File Name Generation) Unless the .Fl f @@ -1831,6 +2032,7 @@ Pathname Expansion, the four varieties of parameter expansion for substring processing and the .Ic case command. +. .Ss Shell Patterns A pattern consists of normal characters, which match themselves, and meta-characters. @@ -1844,6 +2046,7 @@ When command or variable substitution is performed and the dollar sign or back quotes are not double-quoted, the value of the variable or the output of the command is scanned for these characters and they are turned into meta-characters. +. .Pp An asterisk .Pq Ql * @@ -1880,6 +2083,7 @@ the first character of the character class. A caret .Pq Ql ^ has the same effect but is non-standard. +. .Pp To include a .Ql \&] @@ -1892,11 +2096,13 @@ if any). To include a .Ql - , make it the first or last character listed. +. .Ss Built-in Commands This section lists the built-in commands. .Bl -tag -width indent .It Ic \&: A null command that returns a 0 (true) exit value. +. .It Ic \&. Ar file The commands in the specified file are read and executed by the shell. The @@ -1915,11 +2121,13 @@ for the file. If it is not found in the .Va PATH , it is sought in the current working directory. +. .It Ic \&[ A built-in equivalent of .Xr test 1 . This version is documented in .Xr cash-test 1 . +. .It Ic alias Oo Ar name Ns Oo = Ns Ar string Oc ... Oc If .Ar name Ns = Ns Ar string @@ -1942,23 +2150,28 @@ suitable for re-input to the shell. Also see the .Sx Aliases subsection. +. .It Ic bg Op Ar job ... Continue the specified jobs (or the current job if no jobs are given) in the background. +. .It Ic bind Oo Fl aeklrsv Oc Oo Ar key Oo Ar command Oc Oc List or alter key bindings for the line editor. This command is documented in .Xr editrc 5 . +. .It Ic break Op Ar num See the .Sx Flow-Control Constructs subsection. +. .It Ic builtin Ar cmd Op Ar arg ... Execute the specified built-in command, .Ar cmd . This is useful when the user wishes to override a shell function with the same name as a built-in command. +. .It Ic cd Oo Fl L | P Oc Oo Fl e Oc Op Ar directory .It Ic cd Fl Switch to the specified @@ -2003,6 +2216,7 @@ mechanism was used or if .Ar directory was .Fl . +. .Pp If the .Fl P @@ -2017,6 +2231,7 @@ option is specified, .Pa .. is handled logically. This is the default. +. .Pp The .Fl e @@ -2026,15 +2241,18 @@ to return exit status 1 if the full pathname of the new directory cannot be determined reliably or at all. Normally this is not considered an error, although a warning is printed. +. .Pp If changing the directory fails, the exit status is greater than 1. If the directory is changed, the exit status is 0, or also 1 if .Fl e was given. +. .It Ic chdir A synonym for the .Ic cd built-in command. +. .It Ic command Oo Fl p Oc Op Ar utility Op Ar argument ... .It Ic command Oo Fl p Oc Fl v Ar utility .It Ic command Oo Fl p Oc Fl V Ar utility @@ -2045,6 +2263,7 @@ If .Ar utility is a special builtin, it is executed as if it were a regular builtin. +. .Pp If the .Fl p @@ -2052,6 +2271,7 @@ option is specified, the command search is performed using a default value of .Va PATH that is guaranteed to find all of the standard utilities. +. .Pp If the .Fl v @@ -2063,6 +2283,7 @@ For ordinary commands the output is the path name; for shell built-in commands, shell functions and keywords only the name is written. Aliases are printed as .Dq Ic alias Ar name Ns = Ns Ar value . +. .Pp The .Fl V @@ -2083,10 +2304,12 @@ a shell keyword or an alias for .Ar value . +. .It Ic continue Op Ar num See the .Sx Flow-Control Constructs subsection. +. .It Ic echo Oo Fl e | n Oc Op Ar string ... Print a space-separated list of the arguments to the standard output and append a newline character. @@ -2124,6 +2347,7 @@ Literal backslash (Zero) The character whose octal value is .Ar nnn .El +. .Pp If .Ar string @@ -2143,15 +2367,18 @@ $ echo -e a\e\e\e\eb a\eb .Ed .El +. .Pp Only one of the .Fl e and .Fl n options may be specified. +. .It Ic eval Ar string ... Concatenate all the arguments with spaces. Then re-parse and execute the command. +. .It Ic exec Op Ar command Op arg ... Unless .Ar command @@ -2164,6 +2391,7 @@ command are marked as permanent, so that they are not undone when the .Ic exec command finishes. +. .It Ic exit Op Ar exitstatus Terminate the shell process. If @@ -2177,6 +2405,7 @@ if the shell is executing a trap for a signal, the shell exits by resending the signal to itself. Otherwise, the exit status of the preceding command is used. The exit status should be an integer between 0 and 255. +. .It Ic export Ar name ... .It Ic export Op Fl p The specified names are exported so that they will @@ -2198,8 +2427,10 @@ If the option is specified, the exported variables are printed as .Dq Ic export Ar name Ns = Ns Ar value lines, suitable for re-input to the shell. +. .It Ic false A null command that returns a non-zero (false) exit value. +. .It Ic fc Oo Fl e Ar editor Oc Op Ar first Op Ar last .It Ic fc Fl l Oo Fl nr Oc Op Ar first Op Ar last .It Ic fc Fl s Oo Ar old Ns = Ns Ar new Oc Op Ar first @@ -2207,6 +2438,7 @@ The .Ic fc built-in command lists, or edits and re-executes, commands previously entered to an interactive shell. +. .Bl -tag -width indent .It Fl e Ar editor Use the editor named by @@ -2233,6 +2465,7 @@ If is null or unset, .Xr ed 1 is used as the editor. +. .It Fl l No (ell) List the commands rather than invoking an editor on them. @@ -2244,9 +2477,11 @@ and operands, as affected by .Fl r , with each command preceded by the command number. +. .It Fl n Suppress command numbers when listing with .Fl l . +. .It Fl r Reverse the order of the commands listed (with @@ -2256,8 +2491,10 @@ or edited .Fl l nor .Fl s ) . +. .It Fl s Re-execute the command without invoking an editor. +. .It Ar first .It Ar last Select the commands to list or edit. @@ -2270,12 +2507,14 @@ The value of or .Ar last or both are one of the following: +. .Bl -tag -width indent .It Oo Cm + Oc Ns Ar num A positive number representing a command number; command numbers can be displayed with the .Fl l option. +. .It Fl Ar num A negative decimal number representing the command that was executed @@ -2283,6 +2522,7 @@ command that was executed of commands previously. For example, \-1 is the immediately previous command. +. .It Ar string A string indicating the most recently entered command that begins with that string. @@ -2293,6 +2533,7 @@ operand is not also specified with the string form of the first operand cannot contain an embedded equal sign. .El .El +. .Pp The following variables affect the execution of .Ic fc : @@ -2302,10 +2543,12 @@ Name of the editor to use for history editing. .It Va HISTSIZE The number of previous commands that are accessible. .El +. .It Ic fg Op Ar job Move the specified .Ar job or the current job to the foreground. +. .It Ic getopts Ar optstring var The POSIX .Ic getopts @@ -2330,11 +2573,13 @@ is set to It returns a false value (1) when it encounters the end of the options. A new set of arguments may be parsed by assigning .Li OPTIND=1 . +. .It Ic hash Oo Fl rv Oc Op Ar command ... The shell maintains a hash table which remembers the locations of commands. With no arguments whatsoever, the .Ic hash command prints out the contents of this table. +. .Pp With arguments, the .Ic hash @@ -2351,17 +2596,20 @@ The option causes the .Ic hash command to delete all the entries in the hash table except for functions. +. .It Ic jobid Op Ar job Print the process IDs of the processes in the specified .Ar job . If the .Ar job argument is omitted, use the current job. +. .It Ic jobs Oo Fl lps Oc Op Ar job ... Print information about the specified jobs, or all jobs if no .Ar job argument is given. The information printed includes job ID, status and command name. +. .Pp If the .Fl l @@ -2374,21 +2622,25 @@ If the .Fl s option is specified, only the PIDs of the job commands are printed, one per line. +. .It Ic kill A built-in equivalent of .Xr kill 1 that additionally supports sending signals to jobs. This version is documented in .Xr cash-kill 1 . +. .It Ic local Oo Ar variable ... Oc Op Fl See the .Sx Functions subsection. +. .It Ic printf A built-in equivalent of .Xr printf 1 . This version is documented in .Xr cash-printf 1 . +. .It Ic pwd Op Fl L | P Print the path of the current directory. The built-in command may @@ -2402,6 +2654,7 @@ renamed, the built-in version of .Xr pwd 1 will continue to print the old name for the directory. +. .Pp If the .Fl P @@ -2411,6 +2664,7 @@ If the option is specified, the shell's notion of the current directory is printed (symbolic links are not resolved). This is the default. +. .It Ic read Oo Fl p Ar prompt Oc Oo .Fl t Ar timeout Oc Oo Fl er Oc Ar variable ... The @@ -2434,6 +2688,7 @@ that separated them) are assigned to the last variable. If there are more variables than pieces, the remaining variables are assigned the null string. +. .Pp Backslashes are treated specially, unless the .Fl r @@ -2447,6 +2702,7 @@ character, the backslash will be deleted and the following character will be treated as though it were not in .Va IFS , even if it is. +. .Pp If the .Fl t @@ -2469,15 +2725,18 @@ to explicitly specify seconds, minutes or hours. If none is supplied, .Ql s is assumed. +. .Pp The .Fl e option exists only for backward compatibility with older scripts. +. .Pp The exit status is 0 on success, 1 on end of file, between 2 and 128 if an error occurs and greater than 128 if a trapped signal interrupts .Ic read . +. .It Ic readonly Oo Fl p Oc Op Ar name ... Each specified .Ar name @@ -2497,18 +2756,22 @@ If the option is specified, the read-only variables are printed as .Dq Ic readonly Ar name Ns = Ns Ar value lines, suitable for re-input to the shell. +. .It Ic return Op Ar exitstatus See the .Sx Functions subsection. +. .It Ic set Oo Fl /+abCEefIimnpTuVvx Oc Oo Fl /+o Ar longname Oc Oo .Fl c Ar string Oc Op Fl - Ar arg ... The .Ic set command performs three different functions: +. .Bl -item .It With no arguments, it lists the values of all shell variables. +. .It If options are given, either in short form or using the long @@ -2516,6 +2779,7 @@ either in short form or using the long form, it sets or clears the specified options as described in the section called .Sx Argument List Processing . +. .It If the .Dq Fl - @@ -2542,6 +2806,7 @@ which the .Ic set command will interpret as a request to enable or disable options. .El +. .It Ic setvar Ar variable value Assigns the specified .Ar value @@ -2555,6 +2820,7 @@ In general it is better to write .Dq Ar variable Ns = Ns Ar value rather than using .Ic setvar . +. .It Ic shift Op Ar n Shift the positional parameters .Ar n @@ -2575,16 +2841,19 @@ decreasing the value of by one. For portability, shifting if there are zero positional parameters should be avoided, since the shell may abort. +. .It Ic test A built-in equivalent of .Xr test 1 . This version is documented in .Xr cash-test 1 . +. .It Ic times Print the amount of time spent executing the shell process and its children. The first output line shows the user and system times for the shell process itself, the second one contains the user and system times for the children. +. .It Ic trap Oo Ar action Oc Ar signal ... .It Ic trap Fl l Cause the shell to parse and execute @@ -2612,14 +2881,17 @@ the shell resets trapped (but not ignored) signals to the default action. The .Ic trap command has no effect on signals that were ignored on entry to the shell. +. .Pp Option .Fl l causes the .Ic trap command to display a list of valid signal names. +. .It Ic true A null command that returns a 0 (true) exit value. +. .It Ic type Op Ar name ... Interpret each .Ar name @@ -2631,6 +2903,7 @@ and not found. For aliases the alias expansion is printed; for commands and tracked aliases the complete pathname of the command is printed. +. .It Ic ulimit Oo Fl HSabcdfklmnopstuvw Oc Op Ar limit Set or display resource limits (see .Xr getrlimit 2 ) . @@ -2638,6 +2911,7 @@ If .Ar limit is specified, the named resource will be set; otherwise the current resource value will be displayed. +. .Pp If .Fl H @@ -2656,6 +2930,7 @@ or can be given. The default is to display the soft limits, and to set both the hard and the soft limits. +. .Pp Option .Fl a @@ -2665,6 +2940,7 @@ command to display all resources. The parameter .Ar limit is not acceptable in this mode. +. .Pp The remaining options specify which resource value is to be displayed or modified. @@ -2712,6 +2988,7 @@ The maximal virtual size of a process, in kilobytes. The maximum amount of swap space reserved or used for this user ID, in kilobytes. .El +. .It Ic umask Oo Fl S Oc Op Ar mask Set the file creation mask (see .Xr umask 2 ) @@ -2723,11 +3000,13 @@ If the argument is omitted, the current mask value is printed. If the .Fl S option is specified, the output is symbolic, otherwise the output is octal. +. .It Ic unalias Oo Fl a Oc Op Ar name ... The specified alias names are removed. If .Fl a is specified, all aliases are removed. +. .It Ic unset Oo Fl fv Oc Ar name ... The specified variables or functions are unset and unexported. If the @@ -2740,6 +3019,7 @@ If the option is specified, the .Ar name arguments are treated as function names. +. .It Ic wait Op Ar job ... Wait for each specified .Ar job @@ -2753,6 +3033,7 @@ were a known job that exited with exit status 127. If no operands are given, wait for all jobs to complete and return an exit status of zero. .El +. .Ss Command Line Editing When .Nm @@ -2789,6 +3070,7 @@ can be switched between insert mode and command mode by typing Hitting .Aq return while in command mode will pass the line to the shell. +. .Pp Similarly, the .Dq Li "set -o emacs" @@ -2797,34 +3079,42 @@ Similarly, the command can be used to enable a subset of .Nm emacs Ns -style command line editing features. +. .Sh ENVIRONMENT The following environment variables affect the execution of .Nm : +. .Bl -tag -width ".Ev LANGXXXXXX" .It Ev ENV Initialization file for interactive shells. +. .It Ev LANG , Ev LC_* Locale settings. These are inherited by children of the shell, and is used in a limited manner by the shell itself. +. .It Ev OLDPWD The previous current directory. This is used and updated by .Ic cd . +. .It Ev PWD An absolute pathname for the current directory, possibly containing symbolic links. This is used and updated by the shell. +. .It Ev TERM The default terminal setting for the shell. This is inherited by children of the shell, and is used in the history editing modes. .El +. .Pp Additionally, environment variables are turned into shell variables at startup, which may affect the shell as described under .Sx Special Variables . +. .Sh FILES .Bl -tag -width "/etc/suid_profileXX" -compact .It Pa ~/.profile @@ -2836,6 +3126,7 @@ Shell database. .It Pa /etc/suid_profile Privileged shell profile. .El +. .Sh EXIT STATUS Errors that are detected by the shell, such as a syntax error, will cause the shell to exit with a non-zero exit status. @@ -2846,6 +3137,7 @@ executed, or if the .Ic exit builtin is used with a numeric argument, it will return the argument. +. .Sh SEE ALSO .Xr builtin 1 , .Xr chsh 1 , @@ -2863,6 +3155,7 @@ will return the argument. .Xr wctype 3 , .Xr editrc 5 , .Xr shells 5 +. .Sh HISTORY A .Xr sh 1 @@ -2872,6 +3165,7 @@ It was superseded in .At v7 by the Bourne shell, which inherited the name .Xr sh 1 . +. .Pp The .Fx @@ -2881,6 +3175,7 @@ was rewritten in 1989 under the .Bx license after the Bourne shell from .At V.4 . +. .Pp The .Nm @@ -2888,6 +3183,7 @@ utility is based on .Xr sh 1 from .Fx 12.0 . +. .Sh AUTHORS .An -nosplit The @@ -2896,11 +3192,13 @@ version of .Xr sh 1 was originally written by .An Kenneth Almquist . +. .Pp The .Nm utility is developed by .An June McEnroe Aq Mt june@causal.agency . +. .Sh BUGS The .Nm |