From: Chet Ramey Date: Mon, 9 Jan 2012 13:28:43 +0000 (-0500) Subject: commit bash-20110922 snapshot X-Git-Tag: bash-4.3-alpha~104 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b28ff8c95e6c0c7326e8064a45ac380a0551738e;p=thirdparty%2Fbash.git commit bash-20110922 snapshot --- diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 5e0b3a9cc..db9cea044 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -12187,3 +12187,43 @@ builtins/declare.def it as an assignment error and don't attempt any further processing of that declaration. Fixes segfault bug reported by Diego Augusto Molina + + 9/19 + ---- +expr.c + - exppower: replace the simple exponentiation algorithm with an + implementation of exponentiation by squaring. Inspired by report + from Nicolas ARGYROU + +bashline.c + - bash_quote_filename: check for rtext being non-null before + dereferencing it + - set_saved_history: operate_and_get_next assumes that the previous + line was added to the history, even when the history is stifled and + at the max number of entries. If it wasn't, make sure the history + number is incremented properly. Partial fix for bug reported by + gregrwm + +doc/{bash.1,bashref.texi},lib/readline/doc/{hsuser,rluser}.texi + - minor editorial changes inspired by suggestions from + + + 9/20 + ---- +lib/intl/localealias.c + - read_alias_file: close resource leak (fp) when returning on error + + 9/22 + ---- +execute_command.c + - execute_intern_function: implement Posix interpretation 383 by making + it an error to define a function with the same name as a special + builtin when in Posix mode. + http://austingroupbugs.net/view.php?id=383#c692 + + 9/25 + ---- +doc/{bash.1,bashref.texi} + - formatting and some content changes from Benno Schulenberg + + - document new posix-mode behavior from interp 383 change of 9/22 diff --git a/CWRU/CWRU.chlog~ b/CWRU/CWRU.chlog~ index 007fdb2d4..535d56495 100644 --- a/CWRU/CWRU.chlog~ +++ b/CWRU/CWRU.chlog~ @@ -12172,3 +12172,57 @@ bashline.c sh_backslash_quote gets the table with the characters in the variable reference removed, which means they are removed from the set of characters to be quoted in filenames + + 9/10 + ---- +bashline.c + - bash_filename_stat_hook: new function, designed to expand variable + references in filenames before readline passes them to stat(2) + to determine whether or not they are a directory + + 9/15 + ---- +builtins/declare.def + - if assign_array_element fails due to a bad (or empty) subscript, mark + it as an assignment error and don't attempt any further processing + of that declaration. Fixes segfault bug reported by Diego Augusto + Molina + + 9/19 + ---- +expr.c + - exppower: replace the simple exponentiation algorithm with an + implementation of exponentiation by squaring. Inspired by report + from Nicolas ARGYROU + +bashline.c + - bash_quote_filename: check for rtext being non-null before + dereferencing it + - set_saved_history: operate_and_get_next assumes that the previous + line was added to the history, even when the history is stifled and + at the max number of entries. If it wasn't, make sure the history + number is incremented properly. Partial fix for bug reported by + gregrwm + +doc/{bash.1,bashref.texi},lib/readline/doc/{hsuser,rluser}.texi + - minor editorial changes inspired by suggestions from + + + 9/20 + ---- +lib/intl/localealias.c + - read_alias_file: close resource leak (fp) when returning on error + + 9/22 + ---- +execute_command.c + - execute_intern_function: implement Posix interpretation 383 by making + it an error to define a function with the same name as a special + builtin when in Posix mode. + http://austingroupbugs.net/view.php?id=383#c692 + + 9/25 + ---- +doc/{bash.1,bashref.texi} + - formatting and some content changes from Benno Schulenberg + diff --git a/bashline.c b/bashline.c index ca1c9ffbf..a9d56be5a 100644 --- a/bashline.c +++ b/bashline.c @@ -849,12 +849,25 @@ hostnames_matching (text) /* The equivalent of the Korn shell C-o operate-and-get-next-history-line editing command. */ static int saved_history_line_to_use = -1; +static int last_saved_history_line = -1; + +#define HISTORY_FULL() (history_is_stifled () && history_length >= history_max_entries) static int set_saved_history () { + /* XXX - compensate for assumption that history was `shuffled' if it was + actually not. */ + if (HISTORY_FULL () && + hist_last_line_added == 0 && + saved_history_line_to_use < history_length - 1) + saved_history_line_to_use++; + if (saved_history_line_to_use >= 0) - rl_get_previous_history (history_length - saved_history_line_to_use, 0); + { + rl_get_previous_history (history_length - saved_history_line_to_use, 0); + last_saved_history_line = saved_history_line_to_use; + } saved_history_line_to_use = -1; rl_startup_hook = old_rl_startup_hook; return (0); @@ -872,8 +885,7 @@ operate_and_get_next (count, c) /* Find the current line, and find the next line to use. */ where = where_history (); - if ((history_is_stifled () && (history_length >= history_max_entries)) || - (where >= history_length - 1)) + if (HISTORY_FULL () || (where >= history_length - 1)) saved_history_line_to_use = where; else saved_history_line_to_use = where + 1; @@ -3656,9 +3668,17 @@ bash_quote_filename (s, rtype, qcp) /* Leave the opening quote intact. The readline completion code takes care of avoiding doubled opening quotes. */ - rlen = strlen (rtext); - ret = (char *)xmalloc (rlen + 1); - strcpy (ret, rtext); + if (rtext) + { + rlen = strlen (rtext); + ret = (char *)xmalloc (rlen + 1); + strcpy (ret, rtext); + } + else + { + ret = (char *)xmalloc (rlen = 1); + ret[0] = '\0'; + } /* If there are multiple matches, cut off the closing quote. */ if (rtype == MULT_MATCH && cs != COMPLETE_BSQUOTE) diff --git a/doc/bash.1 b/doc/bash.1 index 4be04a6c7..bfe60293d 100644 --- a/doc/bash.1 +++ b/doc/bash.1 @@ -5,12 +5,12 @@ .\" Case Western Reserve University .\" chet@po.cwru.edu .\" -.\" Last Change: Fri Sep 16 08:43:45 EDT 2011 +.\" Last Change: Sun Sep 25 22:01:16 EDT 2011 .\" .\" bash_builtins, strip all but Built-Ins section .if \n(zZ=1 .ig zZ .if \n(zY=1 .ig zY -.TH BASH 1 "2011 September 16" "GNU Bash 4.2" +.TH BASH 1 "2011 September 25" "GNU Bash 4.2" .\" .\" There's some problem with having a `@' .\" in a tagged paragraph with the BSD man macros. @@ -294,7 +294,7 @@ executes its startup files. If any of the files exist but cannot be read, .B bash reports an error. -Tildes are expanded in file names as described below under +Tildes are expanded in filenames as described below under .B "Tilde Expansion" in the .SM @@ -348,7 +348,7 @@ behaves as if the following command were executed: but the value of the .SM .B PATH -variable is not used to search for the file name. +variable is not used to search for the filename. .PP If .B bash @@ -920,7 +920,7 @@ If \fINAME\fP is not supplied, the default name is \fBCOPROC\fP. \fINAME\fP must not be supplied if \fIcommand\fP is a \fIsimple command\fP (see above); otherwise, it is interpreted as the first word of the simple command. -When the coproc is executed, the shell creates an array variable (see +When the coprocess is executed, the shell creates an array variable (see .B Arrays below) named \fINAME\fP in the context of the executing shell. The standard output of @@ -965,6 +965,8 @@ That command is usually a \fIlist\fP of commands between { and }, but may be any command listed under \fBCompound Commands\fP above. \fIcompound\-command\fP is executed whenever \fIname\fP is specified as the name of a simple command. +When in \fIposix mode\fP, \fIname\fP may not be the name of one of the +POSIX \fIspecial builtins\fP. Any redirections (see .SM .B REDIRECTION @@ -1329,7 +1331,7 @@ option, then .B $0 is set to the first argument after the string to be executed, if one is present. Otherwise, it is set -to the file name used to invoke +to the filename used to invoke .BR bash , as given by argument zero. .TP @@ -1351,7 +1353,7 @@ The following variables are set by the shell: .PD 0 .TP .B BASH -Expands to the full file name used to invoke this instance of +Expands to the full filename used to invoke this instance of .BR bash . .TP .B BASHOPTS @@ -1830,10 +1832,10 @@ The value of .SM .B BASH_ENV is subjected to parameter expansion, command substitution, and arithmetic -expansion before being interpreted as a file name. +expansion before being interpreted as a filename. .SM .B PATH -is not used to search for the resultant file name. +is not used to search for the resultant filename. .TP .B BASH_XTRACEFD If set to an integer corresponding to a valid file descriptor, \fBbash\fP @@ -2128,9 +2130,9 @@ If this variable is unset, or set to a value that is not a number greater than or equal to zero, the shell disables mail checking. .TP .B MAILPATH -A colon-separated list of file names to be checked for mail. +A colon-separated list of filenames to be checked for mail. The message to be printed when mail arrives in a particular file -may be specified by separating the file name from the message with a `?'. +may be specified by separating the filename from the message with a `?'. When used in the text of the message, \fB$_\fP expands to the name of the current mailfile. Example: @@ -2393,7 +2395,7 @@ builtins. Each attribute applies to all members of an array. Arrays are assigned to using compound assignments of the form \fIname\fP=\fB(\fPvalue\fI1\fP ... value\fIn\fP\fB)\fP, where each \fIvalue\fP is of the form [\fIsubscript\fP]=\fIstring\fP. -Indexed array assignments do not require the bracket and subscript. +Indexed array assignments do not require anything but \fIstring\fP. When assigning to indexed arrays, if the optional brackets and subscript are supplied, that index is assigned to; otherwise the index of the element assigned is the last index assigned @@ -2646,7 +2648,7 @@ following a or the first .BR = . In these cases, tilde expansion is also performed. -Consequently, one may use file names with tildes in assignments to +Consequently, one may use filenames with tildes in assignments to .SM .BR PATH , .SM @@ -3134,12 +3136,12 @@ If one of these characters appears, then the word is regarded as a .IR pattern , and replaced with an alphabetically sorted list of -file names matching the pattern +filenames matching the pattern (see .SM .B "Pattern Matching" below). -If no matching file names are found, +If no matching filenames are found, and the shell option .B nullglob is not enabled, the word is left unchanged. @@ -3183,16 +3185,16 @@ shell options. The .SM .B GLOBIGNORE -shell variable may be used to restrict the set of file names matching a +shell variable may be used to restrict the set of filenames matching a .IR pattern . If .SM .B GLOBIGNORE -is set, each matching file name that also matches one of the patterns in +is set, each matching filename that also matches one of the patterns in .SM .B GLOBIGNORE is removed from the list of matches. -The file names +The filenames .B ``.'' and .B ``..'' @@ -3204,10 +3206,10 @@ is set and not null. However, setting .B GLOBIGNORE to a non-null value has the effect of enabling the .B dotglob -shell option, so all other file names beginning with a +shell option, so all other filenames beginning with a .B ``.'' will match. -To get the old behavior of ignoring file names beginning with a +To get the old behavior of ignoring filenames beginning with a .BR ``.'' , make .B ``.*'' @@ -4405,7 +4407,7 @@ When .B bash invokes an external command, the variable .B _ -is set to the full file name of the command and passed to that +is set to the full filename of the command and passed to that command in its environment. .SH "EXIT STATUS" .PP @@ -5965,11 +5967,11 @@ will be executed by the shell. .B glob\-complete\-word (M\-g) The word before point is treated as a pattern for pathname expansion, with an asterisk implicitly appended. This pattern is used to -generate a list of matching file names for possible completions. +generate a list of matching filenames for possible completions. .TP .B glob\-expand\-word (C\-x *) The word before point is treated as a pattern for pathname expansion, -and the list of matching file names is inserted, replacing the word. +and the list of matching filenames is inserted, replacing the word. If a numeric argument is supplied, an asterisk is appended before pathname expansion. .TP @@ -6513,10 +6515,10 @@ one or more of the following modifiers, each preceded by a `:'. .PP .TP .B h -Remove a trailing file name component, leaving only the head. +Remove a trailing filename component, leaving only the head. .TP .B t -Remove all leading file name components, leaving the tail. +Remove all leading filename components, leaving the tail. .TP .B r Remove a trailing suffix of the form \fI.xxx\fP, leaving the @@ -6620,7 +6622,7 @@ executed from .IR filename . If .I filename -does not contain a slash, file names in +does not contain a slash, filenames in .SM .B PATH are used to find the directory containing @@ -6900,7 +6902,7 @@ option is supplied, a description of .I command is printed. The .B \-v -option causes a single word indicating the command or file name +option causes a single word indicating the command or filename used to invoke .I command to be displayed; the @@ -7263,11 +7265,15 @@ turns off the attribute instead, with the exceptions that \fB+a\fP may not be used to destroy an array variable and \fB+r\fP will not remove the readonly attribute. -When used in a function, makes each +When used in a function, +.B declare +and +.B typeset +make each \fIname\fP local, as with the .B local command, -unless the \fB\-g\fP option is supplied, +unless the \fB\-g\fP option is supplied. If a variable name is followed by =\fIvalue\fP, the value of the variable is set to \fIvalue\fP. The return value is 0 unless an invalid option is encountered, @@ -7284,7 +7290,7 @@ an attempt is made to turn off array status for an array variable, or an attempt is made to display a non-existent function with \fB\-f\fP. .RE .TP -.B dirs [+\fIn\fP] [\-\fIn\fP] [\fB\-clpv\fP] +.B dirs [\fB\-clpv\fP] [+\fIn\fP] [\-\fIn\fP] Without options, displays the list of currently remembered directories. The default display is on a single line with directory names separated by spaces. @@ -7296,24 +7302,12 @@ command removes entries from the list. .RS .PD 0 .TP -\fB+\fP\fIn\fP -Displays the \fIn\fPth entry counting from the left of the list -shown by -.B dirs -when invoked without options, starting with zero. -.TP -\fB\-\fP\fIn\fP -Displays the \fIn\fPth entry counting from the right of the list -shown by -.B dirs -when invoked without options, starting with zero. -.TP .B \-c Clears the directory stack by deleting all of the entries. .TP .B \-l -Produces a longer listing; the default listing format uses a -tilde to denote the home directory. +Produces a listing using full pathnames; +the default listing format uses a tilde to denote the home directory. .TP .B \-p Print the directory stack with one entry per line. @@ -7321,6 +7315,18 @@ Print the directory stack with one entry per line. .B \-v Print the directory stack with one entry per line, prefixing each entry with its index in the stack. +.TP +\fB+\fP\fIn\fP +Displays the \fIn\fPth entry counting from the left of the list +shown by +.B dirs +when invoked without options, starting with zero. +.TP +\fB\-\fP\fIn\fP +Displays the \fIn\fPth entry counting from the right of the list +shown by +.B dirs +when invoked without options, starting with zero. .PD .PP The return value is 0 unless an @@ -7329,9 +7335,9 @@ of the directory stack. .RE .TP \fBdisown\fP [\fB\-ar\fP] [\fB\-h\fP] [\fIjobspec\fP ...] -Without options, each +Without options, remove each .I jobspec -is removed from the table of active jobs. +from the table of active jobs. If .I jobspec is not present, and neither \fB\-a\fP nor \fB\-r\fP is supplied, @@ -7506,12 +7512,14 @@ to be executed with an empty environment. If .B \-a is supplied, the shell passes .I name -as the zeroth argument to the executed command. If +as the zeroth argument to the executed command. +If .I command cannot be executed for some reason, a non-interactive shell exits, -unless the shell option +unless the .B execfail -is enabled, in which case it returns failure. +shell option +is enabled. In that case, it returns failure. An interactive shell returns failure if the file cannot be executed. If .I command @@ -7549,7 +7557,7 @@ If no are given, or if the .B \-p option is supplied, a list -of all names that are exported in this shell is printed. +of names of all exported variables is printed. The .B \-n option causes the export property to be removed from each @@ -7570,11 +7578,11 @@ that is not a function. .TP \fBfc\fP \fB\-s\fP [\fIpat\fP=\fIrep\fP] [\fIcmd\fP] .PD -Fix Command. In the first form, a range of commands from +The first form selects a range of commands from .I first to .I last -is selected from the history list. +from the history list and displays or edits and re-executes them. .I First and .I last @@ -7628,6 +7636,7 @@ echoed and executed. .sp 1 In the second form, \fIcommand\fP is re-executed after each instance of \fIpat\fP is replaced by \fIrep\fP. +\fICommand\fP is intepreted the same as \fIfirst\fP above. A useful alias to use with this is .if n ``r="fc -s"'', .if t \f(CWr='fc \-s'\fP, @@ -7730,7 +7739,7 @@ can report errors in two ways. If the first character of .I optstring is a colon, .I silent -error reporting is used. In normal operation diagnostic messages +error reporting is used. In normal operation, diagnostic messages are printed when invalid options or missing option arguments are encountered. If the variable @@ -7791,7 +7800,7 @@ If the .B \-p option is supplied, no path search is performed, and .I filename -is used as the full file name of the command. +is used as the full filename of the command. The .B \-r option causes the shell to forget all @@ -7895,10 +7904,10 @@ current \fBbash\fP session. .TP .B \-r Read the contents of the history file -and use them as the current history. +and append them to the current history list. .TP .B \-w -Write the current history to the history file, overwriting the +Write the current history list to the history file, overwriting the history file's contents. .TP .B \-p @@ -7954,10 +7963,10 @@ List only the process ID of the job's process group leader. .TP .B \-r -Restrict output to running jobs. +Display only running jobs. .TP .B \-s -Restrict output to stopped jobs. +Display only stopped jobs. .PD .PP If @@ -8455,21 +8464,26 @@ is supplied with a that is not a function. .TP \fBreturn\fP [\fIn\fP] -Causes a function to exit with the return value specified by -.IR n . +Causes a function to stop executing and return the value specified by +.I n +to its caller. If .I n is omitted, the return status is that of the last command -executed in the function body. If used outside a function, +executed in the function body. If +.B return +is used outside a function, but during execution of a script by the .B . (\fBsource\fP) command, it causes the shell to stop executing that script and return either .I n or the exit status of the last command executed within the -script as the exit status of the script. If used outside a -function and not during execution of a script by \fB.\fP\^, -the return status is false. +script as the exit status of the script. +The return status is non-zero if +.B return +is used outside a +function and not during execution of a script by \fB.\fP\^ or \fBsource\fP. Any command associated with the \fBRETURN\fP trap is executed before execution resumes after the function or script. .TP @@ -8891,8 +8905,9 @@ If either .B \-s or .B \-u -is used with no \fIoptname\fP arguments, the display is limited to -those options which are set or unset, respectively. +is used with no \fIoptname\fP arguments, +.B shopt +shows only those options which are set or unset, respectively. Unless otherwise noted, the \fBshopt\fP options are disabled (unset) by default. .PP @@ -8924,7 +8939,7 @@ If set, minor errors in the spelling of a directory component in a command will be corrected. The errors checked for are transposed characters, a missing character, and one character too many. -If a correction is found, the corrected file name is printed, +If a correction is found, the corrected filename is printed, and the command proceeds. This option is only used by interactive shells. .TP 8 @@ -9299,7 +9314,7 @@ is not supplied, or if job control is not enabled. .PD 0 .TP \fB[\fP \fIexpr\fP \fB]\fP -Return a status of 0 or 1 depending on +Return a status of 0 (true) or 1 (false) depending on the evaluation of the conditional expression .IR expr . Each operator and operand must be a separate argument. @@ -9570,7 +9585,7 @@ If a command is hashed, .B \-p and .B \-P -print the hashed value, not necessarily the file that appears +print the hashed value, which is not necessarily the file that appears first in .SM .BR PATH . @@ -9685,16 +9700,17 @@ The maximum number of threads .PP If .I limit -is given, it is the new value of the specified resource (the +is given, and the .B \-a -option is display only). +option is not used, +\fIlimit\fP is the new value of the specified resource. If no option is given, then .B \-f is assumed. Values are in 1024-byte increments, except for .BR \-t , -which is in seconds, +which is in seconds; .BR \-p , -which is in units of 512-byte blocks, +which is in units of 512-byte blocks; and .BR \-T , .BR \-b , @@ -9833,7 +9849,7 @@ or specifying command names containing .B / .IP \(bu -specifying a file name containing a +specifying a filename containing a .B / as an argument to the .B . diff --git a/doc/bash.1~ b/doc/bash.1~ index 6c889d04e..3a61ea485 100644 --- a/doc/bash.1~ +++ b/doc/bash.1~ @@ -5,12 +5,12 @@ .\" Case Western Reserve University .\" chet@po.cwru.edu .\" -.\" Last Change: Tue Aug 16 20:43:02 EDT 2011 +.\" Last Change: Sun Sep 25 22:01:16 EDT 2011 .\" .\" bash_builtins, strip all but Built-Ins section .if \n(zZ=1 .ig zZ .if \n(zY=1 .ig zY -.TH BASH 1 "2011 August 16" "GNU Bash 4.2" +.TH BASH 1 "2011 September 25" "GNU Bash 4.2" .\" .\" There's some problem with having a `@' .\" in a tagged paragraph with the BSD man macros. @@ -294,7 +294,7 @@ executes its startup files. If any of the files exist but cannot be read, .B bash reports an error. -Tildes are expanded in file names as described below under +Tildes are expanded in filenames as described below under .B "Tilde Expansion" in the .SM @@ -348,7 +348,7 @@ behaves as if the following command were executed: but the value of the .SM .B PATH -variable is not used to search for the file name. +variable is not used to search for the filename. .PP If .B bash @@ -530,11 +530,12 @@ command (see .SM .B REDIRECTION below). -If \fB|&\fP is used, the standard error of \fIcommand\fP is connected to -\fIcommand2\fP's standard input through the pipe; it is shorthand for -\fB2>&1 |\fP. -This implicit redirection of the standard error is performed after any -redirections specified by the command. +If \fB|&\fP is used, \fIcommand\fP's standard output and standard error +are connected to +\fIcommand2\fP's standard input through the pipe; +it is shorthand for \fB2>&1 |\fP. +This implicit redirection of the standard error is +performed after any redirections specified by the command. .PP The return status of a pipeline is the exit status of the last command, unless the \fBpipefail\fP option is enabled. @@ -919,7 +920,7 @@ If \fINAME\fP is not supplied, the default name is \fBCOPROC\fP. \fINAME\fP must not be supplied if \fIcommand\fP is a \fIsimple command\fP (see above); otherwise, it is interpreted as the first word of the simple command. -When the coproc is executed, the shell creates an array variable (see +When the coprocess is executed, the shell creates an array variable (see .B Arrays below) named \fINAME\fP in the context of the executing shell. The standard output of @@ -1328,7 +1329,7 @@ option, then .B $0 is set to the first argument after the string to be executed, if one is present. Otherwise, it is set -to the file name used to invoke +to the filename used to invoke .BR bash , as given by argument zero. .TP @@ -1350,7 +1351,7 @@ The following variables are set by the shell: .PD 0 .TP .B BASH -Expands to the full file name used to invoke this instance of +Expands to the full filename used to invoke this instance of .BR bash . .TP .B BASHOPTS @@ -1829,10 +1830,10 @@ The value of .SM .B BASH_ENV is subjected to parameter expansion, command substitution, and arithmetic -expansion before being interpreted as a file name. +expansion before being interpreted as a filename. .SM .B PATH -is not used to search for the resultant file name. +is not used to search for the resultant filename. .TP .B BASH_XTRACEFD If set to an integer corresponding to a valid file descriptor, \fBbash\fP @@ -2127,9 +2128,9 @@ If this variable is unset, or set to a value that is not a number greater than or equal to zero, the shell disables mail checking. .TP .B MAILPATH -A colon-separated list of file names to be checked for mail. +A colon-separated list of filenames to be checked for mail. The message to be printed when mail arrives in a particular file -may be specified by separating the file name from the message with a `?'. +may be specified by separating the filename from the message with a `?'. When used in the text of the message, \fB$_\fP expands to the name of the current mailfile. Example: @@ -2392,7 +2393,7 @@ builtins. Each attribute applies to all members of an array. Arrays are assigned to using compound assignments of the form \fIname\fP=\fB(\fPvalue\fI1\fP ... value\fIn\fP\fB)\fP, where each \fIvalue\fP is of the form [\fIsubscript\fP]=\fIstring\fP. -Indexed array assignments do not require the bracket and subscript. +Indexed array assignments do not require anything but \fIstring\fP. When assigning to indexed arrays, if the optional brackets and subscript are supplied, that index is assigned to; otherwise the index of the element assigned is the last index assigned @@ -2645,7 +2646,7 @@ following a or the first .BR = . In these cases, tilde expansion is also performed. -Consequently, one may use file names with tildes in assignments to +Consequently, one may use filenames with tildes in assignments to .SM .BR PATH , .SM @@ -3133,12 +3134,12 @@ If one of these characters appears, then the word is regarded as a .IR pattern , and replaced with an alphabetically sorted list of -file names matching the pattern +filenames matching the pattern (see .SM .B "Pattern Matching" below). -If no matching file names are found, +If no matching filenames are found, and the shell option .B nullglob is not enabled, the word is left unchanged. @@ -3182,16 +3183,16 @@ shell options. The .SM .B GLOBIGNORE -shell variable may be used to restrict the set of file names matching a +shell variable may be used to restrict the set of filenames matching a .IR pattern . If .SM .B GLOBIGNORE -is set, each matching file name that also matches one of the patterns in +is set, each matching filename that also matches one of the patterns in .SM .B GLOBIGNORE is removed from the list of matches. -The file names +The filenames .B ``.'' and .B ``..'' @@ -3203,10 +3204,10 @@ is set and not null. However, setting .B GLOBIGNORE to a non-null value has the effect of enabling the .B dotglob -shell option, so all other file names beginning with a +shell option, so all other filenames beginning with a .B ``.'' will match. -To get the old behavior of ignoring file names beginning with a +To get the old behavior of ignoring filenames beginning with a .BR ``.'' , make .B ``.*'' @@ -3395,9 +3396,10 @@ the redirection refers to the standard output (file descriptor 1). .PP The word following the redirection operator in the following -descriptions, unless otherwise noted, is subjected to brace expansion, -tilde expansion, parameter expansion, command substitution, arithmetic -expansion, quote removal, pathname expansion, and word splitting. +descriptions, unless otherwise noted, is subjected to +brace expansion, tilde expansion, parameter and variable expansion, +command substitution, arithmetic expansion, quote removal, +pathname expansion, and word splitting. If it expands to more than one word, .B bash reports an error. @@ -3599,8 +3601,8 @@ The format of here-documents is: .fi .RE .PP -No parameter expansion, command substitution, arithmetic expansion, -or pathname expansion is performed on +No parameter and variable expansion, command substitution, +arithmetic expansion, or pathname expansion is performed on .IR word . If any characters in .I word @@ -3639,10 +3641,12 @@ A variant of here documents, the format is: .fi .RE .PP -The \fIword\fP -is expanded as described above, with the exception that -pathname expansion is not applied, and supplied as a single string -to the command on its standard input. +The \fIword\fP undergoes +brace expansion, tilde expansion, parameter and variable expansion, +command substitution, arithmetic expansion, and quote removal. +Pathname expansion word splitting are not performed. +The result is supplied as a single string to the command on its +standard input. .SS "Duplicating File Descriptors" .PP The redirection operator @@ -4401,7 +4405,7 @@ When .B bash invokes an external command, the variable .B _ -is set to the full file name of the command and passed to that +is set to the full filename of the command and passed to that command in its environment. .SH "EXIT STATUS" .PP @@ -5961,11 +5965,11 @@ will be executed by the shell. .B glob\-complete\-word (M\-g) The word before point is treated as a pattern for pathname expansion, with an asterisk implicitly appended. This pattern is used to -generate a list of matching file names for possible completions. +generate a list of matching filenames for possible completions. .TP .B glob\-expand\-word (C\-x *) The word before point is treated as a pattern for pathname expansion, -and the list of matching file names is inserted, replacing the word. +and the list of matching filenames is inserted, replacing the word. If a numeric argument is supplied, an asterisk is appended before pathname expansion. .TP @@ -6509,10 +6513,10 @@ one or more of the following modifiers, each preceded by a `:'. .PP .TP .B h -Remove a trailing file name component, leaving only the head. +Remove a trailing filename component, leaving only the head. .TP .B t -Remove all leading file name components, leaving the tail. +Remove all leading filename components, leaving the tail. .TP .B r Remove a trailing suffix of the form \fI.xxx\fP, leaving the @@ -6616,7 +6620,7 @@ executed from .IR filename . If .I filename -does not contain a slash, file names in +does not contain a slash, filenames in .SM .B PATH are used to find the directory containing @@ -6896,7 +6900,7 @@ option is supplied, a description of .I command is printed. The .B \-v -option causes a single word indicating the command or file name +option causes a single word indicating the command or filename used to invoke .I command to be displayed; the @@ -7259,11 +7263,15 @@ turns off the attribute instead, with the exceptions that \fB+a\fP may not be used to destroy an array variable and \fB+r\fP will not remove the readonly attribute. -When used in a function, makes each +When used in a function, +.B declare +and +.B typeset +make each \fIname\fP local, as with the .B local command, -unless the \fB\-g\fP option is supplied, +unless the \fB\-g\fP option is supplied. If a variable name is followed by =\fIvalue\fP, the value of the variable is set to \fIvalue\fP. The return value is 0 unless an invalid option is encountered, @@ -7280,7 +7288,7 @@ an attempt is made to turn off array status for an array variable, or an attempt is made to display a non-existent function with \fB\-f\fP. .RE .TP -.B dirs [+\fIn\fP] [\-\fIn\fP] [\fB\-clpv\fP] +.B dirs [\fB\-clpv\fP] [+\fIn\fP] [\-\fIn\fP] Without options, displays the list of currently remembered directories. The default display is on a single line with directory names separated by spaces. @@ -7292,24 +7300,12 @@ command removes entries from the list. .RS .PD 0 .TP -\fB+\fP\fIn\fP -Displays the \fIn\fPth entry counting from the left of the list -shown by -.B dirs -when invoked without options, starting with zero. -.TP -\fB\-\fP\fIn\fP -Displays the \fIn\fPth entry counting from the right of the list -shown by -.B dirs -when invoked without options, starting with zero. -.TP .B \-c Clears the directory stack by deleting all of the entries. .TP .B \-l -Produces a longer listing; the default listing format uses a -tilde to denote the home directory. +Produces a listing using full pathnames; +the default listing format uses a tilde to denote the home directory. .TP .B \-p Print the directory stack with one entry per line. @@ -7317,6 +7313,18 @@ Print the directory stack with one entry per line. .B \-v Print the directory stack with one entry per line, prefixing each entry with its index in the stack. +.TP +\fB+\fP\fIn\fP +Displays the \fIn\fPth entry counting from the left of the list +shown by +.B dirs +when invoked without options, starting with zero. +.TP +\fB\-\fP\fIn\fP +Displays the \fIn\fPth entry counting from the right of the list +shown by +.B dirs +when invoked without options, starting with zero. .PD .PP The return value is 0 unless an @@ -7325,9 +7333,9 @@ of the directory stack. .RE .TP \fBdisown\fP [\fB\-ar\fP] [\fB\-h\fP] [\fIjobspec\fP ...] -Without options, each +Without options, remove each .I jobspec -is removed from the table of active jobs. +from the table of active jobs. If .I jobspec is not present, and neither \fB\-a\fP nor \fB\-r\fP is supplied, @@ -7502,12 +7510,14 @@ to be executed with an empty environment. If .B \-a is supplied, the shell passes .I name -as the zeroth argument to the executed command. If +as the zeroth argument to the executed command. +If .I command cannot be executed for some reason, a non-interactive shell exits, -unless the shell option +unless the .B execfail -is enabled, in which case it returns failure. +shell option +is enabled. In that case, it returns failure. An interactive shell returns failure if the file cannot be executed. If .I command @@ -7545,7 +7555,7 @@ If no are given, or if the .B \-p option is supplied, a list -of all names that are exported in this shell is printed. +of names of all exported variables is printed. The .B \-n option causes the export property to be removed from each @@ -7566,11 +7576,11 @@ that is not a function. .TP \fBfc\fP \fB\-s\fP [\fIpat\fP=\fIrep\fP] [\fIcmd\fP] .PD -Fix Command. In the first form, a range of commands from +The first form selects a range of commands from .I first to .I last -is selected from the history list. +from the history list and displays or edits and re-executes them. .I First and .I last @@ -7624,6 +7634,7 @@ echoed and executed. .sp 1 In the second form, \fIcommand\fP is re-executed after each instance of \fIpat\fP is replaced by \fIrep\fP. +\fICommand\fP is intepreted the same as \fIfirst\fP above. A useful alias to use with this is .if n ``r="fc -s"'', .if t \f(CWr='fc \-s'\fP, @@ -7726,7 +7737,7 @@ can report errors in two ways. If the first character of .I optstring is a colon, .I silent -error reporting is used. In normal operation diagnostic messages +error reporting is used. In normal operation, diagnostic messages are printed when invalid options or missing option arguments are encountered. If the variable @@ -7787,7 +7798,7 @@ If the .B \-p option is supplied, no path search is performed, and .I filename -is used as the full file name of the command. +is used as the full filename of the command. The .B \-r option causes the shell to forget all @@ -7891,10 +7902,10 @@ current \fBbash\fP session. .TP .B \-r Read the contents of the history file -and use them as the current history. +and append them to the current history list. .TP .B \-w -Write the current history to the history file, overwriting the +Write the current history list to the history file, overwriting the history file's contents. .TP .B \-p @@ -7950,10 +7961,10 @@ List only the process ID of the job's process group leader. .TP .B \-r -Restrict output to running jobs. +Display only running jobs. .TP .B \-s -Restrict output to stopped jobs. +Display only stopped jobs. .PD .PP If @@ -8390,8 +8401,9 @@ the decimal point. This option is only effective if \fBread\fP is reading input from a terminal, pipe, or other special file; it has no effect when reading from regular files. -If \fItimeout\fP is 0, \fBread\fP returns success if input is available on -the specified file descriptor, failure otherwise. +If \fItimeout\fP is 0, \fBread\fP returns immediately, without trying to +read any data. The exit statis is 0 if input is available on +the specified file descriptor, non-zero otherwise. The exit status is greater than 128 if the timeout is exceeded. .TP .B \-u \fIfd\fP @@ -8450,21 +8462,26 @@ is supplied with a that is not a function. .TP \fBreturn\fP [\fIn\fP] -Causes a function to exit with the return value specified by -.IR n . +Causes a function to stop executing and return the value specified by +.I n +to its caller. If .I n is omitted, the return status is that of the last command -executed in the function body. If used outside a function, +executed in the function body. If +.B return +is used outside a function, but during execution of a script by the .B . (\fBsource\fP) command, it causes the shell to stop executing that script and return either .I n or the exit status of the last command executed within the -script as the exit status of the script. If used outside a -function and not during execution of a script by \fB.\fP\^, -the return status is false. +script as the exit status of the script. +The return status is non-zero if +.B return +is used outside a +function and not during execution of a script by \fB.\fP\^ or \fBsource\fP. Any command associated with the \fBRETURN\fP trap is executed before execution resumes after the function or script. .TP @@ -8886,8 +8903,9 @@ If either .B \-s or .B \-u -is used with no \fIoptname\fP arguments, the display is limited to -those options which are set or unset, respectively. +is used with no \fIoptname\fP arguments, +.B shopt +shows only those options which are set or unset, respectively. Unless otherwise noted, the \fBshopt\fP options are disabled (unset) by default. .PP @@ -8919,7 +8937,7 @@ If set, minor errors in the spelling of a directory component in a command will be corrected. The errors checked for are transposed characters, a missing character, and one character too many. -If a correction is found, the corrected file name is printed, +If a correction is found, the corrected filename is printed, and the command proceeds. This option is only used by interactive shells. .TP 8 @@ -8989,6 +9007,25 @@ parameter expansion as a special character. The single quotes must match quoted. This is the behavior of posix mode through version 4.1. The default bash behavior remains as in previous versions. .TP 8 +.B complete_fullquote +If set, +.B bash +quotes all shell metacharacters in filenames and directory names when +performing completion. +If not set, +.B bash +removes metacharacters such as the dollar sign from the set of +characters that will be quoted in completed filenames +when these metacharacters appear in shell variable references in words to be +completed. +This means that dollar signs in variable names that expand to directories +will not be quoted; +however, any dollar signs appearing in filenames will not be quoted, either. +This is active only when bash is using backslashes to quote completed +filenames. +This variable is set by default, which is the default bash behavior in +versions through 4.2. +.TP 8 .B direxpand If set, .B bash @@ -9275,7 +9312,7 @@ is not supplied, or if job control is not enabled. .PD 0 .TP \fB[\fP \fIexpr\fP \fB]\fP -Return a status of 0 or 1 depending on +Return a status of 0 (true) or 1 (false) depending on the evaluation of the conditional expression .IR expr . Each operator and operand must be a separate argument. @@ -9546,7 +9583,7 @@ If a command is hashed, .B \-p and .B \-P -print the hashed value, not necessarily the file that appears +print the hashed value, which is not necessarily the file that appears first in .SM .BR PATH . @@ -9661,16 +9698,17 @@ The maximum number of threads .PP If .I limit -is given, it is the new value of the specified resource (the +is given, and the .B \-a -option is display only). +option is not used, +\fIlimit\fP is the new value of the specified resource. If no option is given, then .B \-f is assumed. Values are in 1024-byte increments, except for .BR \-t , -which is in seconds, +which is in seconds; .BR \-p , -which is in units of 512-byte blocks, +which is in units of 512-byte blocks; and .BR \-T , .BR \-b , @@ -9809,7 +9847,7 @@ or specifying command names containing .B / .IP \(bu -specifying a file name containing a +specifying a filename containing a .B / as an argument to the .B . diff --git a/doc/bashref.texi b/doc/bashref.texi index 79fd38ffa..ec4cc91c5 100644 --- a/doc/bashref.texi +++ b/doc/bashref.texi @@ -85,7 +85,7 @@ Bash contains features that appear in other popular shells, and some features that only appear in Bash. Some of the shells that Bash has borrowed concepts from are the Bourne Shell (@file{sh}), the Korn Shell (@file{ksh}), and the C-shell (@file{csh} and its successor, -@file{tcsh}). The following menu breaks the features up into +@file{tcsh}). The following menu breaks the features up into categories based upon which one of these other shells inspired the feature. @@ -627,7 +627,7 @@ the control operators @samp{|} or @samp{|&}. @cindex command timing The format for a pipeline is @example -[@code{time} [@code{-p}]] [@code{!}] @var{command1} [ [@code{|} or @code{|&}] @var{command2} @dots{}] +[time [-p]] [!] @var{command1} [ | or |& @var{command2} ] @dots{} @end example @noindent @@ -777,9 +777,11 @@ command's syntax, it may be replaced with one or more newlines. @rwindex do @rwindex done The syntax of the @code{until} command is: + @example until @var{test-commands}; do @var{consequent-commands}; done @end example + Execute @var{consequent-commands} as long as @var{test-commands} has an exit status which is not zero. The return status is the exit status of the last command executed @@ -788,6 +790,7 @@ in @var{consequent-commands}, or zero if none was executed. @item while @rwindex while The syntax of the @code{while} command is: + @example while @var{test-commands}; do @var{consequent-commands}; done @end example @@ -804,6 +807,7 @@ The syntax of the @code{for} command is: @example for @var{name} [ [in [@var{words} @dots{}] ] ; ] do @var{commands}; done @end example + Expand @var{words}, and execute @var{commands} once for each member in the resultant list, with @var{name} bound to the current member. If @samp{in @var{words}} is not present, the @code{for} command @@ -819,6 +823,7 @@ An alternate form of the @code{for} command is also supported: @example for (( @var{expr1} ; @var{expr2} ; @var{expr3} )) ; do @var{commands} ; done @end example + First, the arithmetic expression @var{expr1} is evaluated according to the rules described below (@pxref{Shell Arithmetic}). The arithmetic expression @var{expr2} is then evaluated repeatedly @@ -828,7 +833,6 @@ executed and the arithmetic expression @var{expr3} is evaluated. If any expression is omitted, it behaves as if it evaluates to 1. The return value is the exit status of the last command in @var{commands} that is executed, or false if any of the expressions is invalid. - @end table The @code{break} and @code{continue} builtins (@pxref{Bourne Shell Builtins}) @@ -875,7 +879,7 @@ zero if no condition tested true. The syntax of the @code{case} command is: @example -@code{case @var{word} in [ [(] @var{pattern} [| @var{pattern}]@dots{}) @var{command-list} ;;]@dots{} esac} +case @var{word} in [ [(] @var{pattern} [| @var{pattern}]@dots{}) @var{command-list} ;;]@dots{} esac @end example @code{case} will selectively execute the @var{command-list} corresponding to @@ -1054,11 +1058,11 @@ True if both @var{expression1} and @var{expression2} are true. @item @var{expression1} || @var{expression2} True if either @var{expression1} or @var{expression2} is true. @end table + @noindent -The @code{&&} and @code{||} operators do not evaluate @var{expression2} if the +The @code{&&} and @code{||} operators do not evaluate @var{[Bexpression2} if the value of @var{expression1} is sufficient to determine the return value of the entire conditional expression. - @end table @node Command Grouping @@ -1117,7 +1121,7 @@ established between the executing shell and the coprocess. The format for a coprocess is: @example -@code{coproc} [@var{NAME}] @var{command} [@var{redirections}] +coproc [@var{NAME}] @var{command} [@var{redirections}] @end example @noindent @@ -1127,22 +1131,22 @@ If @var{NAME} is not supplied, the default name is @var{COPROC}. command (@pxref{Simple Commands}); otherwise, it is interpreted as the first word of the simple command. -When the coproc is executed, the shell creates an array variable +When the coprocess is executed, the shell creates an array variable (@pxref{Arrays}) -named @var{NAME} in the context of the executing shell. +named @env{NAME} in the context of the executing shell. The standard output of @var{command} is connected via a pipe to a file descriptor in the executing shell, -and that file descriptor is assigned to @var{NAME}[0]. +and that file descriptor is assigned to @env{NAME}[0]. The standard input of @var{command} is connected via a pipe to a file descriptor in the executing shell, -and that file descriptor is assigned to @var{NAME}[1]. +and that file descriptor is assigned to @env{NAME}[1]. This pipe is established before any redirections specified by the command (@pxref{Redirections}). The file descriptors can be utilized as arguments to shell commands and redirections using standard word expansions. The process ID of the shell spawned to execute the coprocess is -available as the value of the variable @var{NAME}_PID. +available as the value of the variable @env{NAME}_PID. The @code{wait} builtin command may be used to wait for the coprocess to terminate. @@ -1239,8 +1243,13 @@ shell context; no new process is created to interpret them. Functions are declared using this syntax: @rwindex function @example -@var{name} () @var{compound-command} [ @var{redirections} ]@*or@* -@code{function} @var{name} [()] @var{compound-command} [ @var{redirections} ] +@var{name} () @var{compound-command} [ @var{redirections} ] +@end example + +or + +@example +function @var{name} [()] @var{compound-command} [ @var{redirections} ] @end example This defines a shell function named @var{name}. The reserved @@ -1253,6 +1262,9 @@ That command is usually a @var{list} enclosed between @{ and @}, but may be any compound command listed above. @var{compound-command} is executed whenever @var{name} is specified as the name of a command. +When the shell is in @sc{posix} mode (@pxref{Bash POSIX Mode}), +@var{name} may not be the same as one of the special builtins +(@pxref{Special Builtins}). Any redirections (@pxref{Redirections}) associated with the shell function are performed when the function is executed. @@ -1320,8 +1332,8 @@ Variables local to the function may be declared with the the function and the commands it invokes. Function names and definitions may be listed with the -@option{-f} option to the @code{declare} or @code{typeset} -builtin commands (@pxref{Bash Builtins}). +@option{-f} option to the @code{declare} (@code{typeset}) +builtin command (@pxref{Bash Builtins}). The @option{-F} option to @code{declare} or @code{typeset} will list the function names only (and optionally the source file and line number, if the @code{extdebug} @@ -1507,6 +1519,7 @@ When checking mail, this parameter holds the name of the mail file. Expansion is performed on the command line after it has been split into @code{token}s. There are seven kinds of expansion performed: + @itemize @bullet @item brace expansion @item tilde expansion @@ -1561,7 +1574,7 @@ is performed. Brace expansion is a mechanism by which arbitrary strings may be generated. This mechanism is similar to @var{filename expansion} (@pxref{Filename Expansion}), -but the file names generated need not exist. +but the filenames generated need not exist. Patterns to be brace expanded take the form of an optional @var{preamble}, followed by either a series of comma-separated strings or a sequence expression between a pair of braces, @@ -1661,7 +1674,7 @@ left unchanged. Each variable assignment is checked for unquoted tilde-prefixes immediately following a @samp{:} or the first @samp{=}. In these cases, tilde expansion is also performed. -Consequently, one may use file names with tildes in assignments to +Consequently, one may use filenames with tildes in assignments to @env{PATH}, @env{MAILPATH}, and @env{CDPATH}, and the shell assigns the expanded value. @@ -1691,7 +1704,6 @@ The string that would be displayed by @samp{dirs +@var{N}} @item ~-@var{N} The string that would be displayed by @samp{dirs -@var{N}} - @end table @node Shell Parameter Expansion @@ -1905,7 +1917,6 @@ If @var{parameter} is an array variable subscripted with @samp{@@} or @samp{*}, the case modification operation is applied to each member of the array in turn, and the expansion is the resultant list. - @end table @node Command Substitution @@ -2053,8 +2064,8 @@ After word splitting, unless the @option{-f} option has been set If one of these characters appears, then the word is regarded as a @var{pattern}, and replaced with an alphabetically sorted list of -file names matching the pattern (@pxref{Pattern Matching}). -If no matching file names are found, +filenames matching the pattern (@pxref{Pattern Matching}). +If no matching filenames are found, and the shell option @code{nullglob} is disabled, the word is left unchanged. If the @code{nullglob} option is set, and no matches are found, the word @@ -2067,7 +2078,7 @@ without regard to the case of alphabetic characters. When a pattern is used for filename expansion, the character @samp{.} at the start of a filename or immediately following a slash must be matched explicitly, unless the shell option @code{dotglob} is set. -When matching a file name, the slash character must always be +When matching a filename, the slash character must always be matched explicitly. In other cases, the @samp{.} character is not treated specially. @@ -2270,7 +2281,6 @@ connection to the corresponding socket. If @var{host} is a valid hostname or Internet address, and @var{port} is an integer port number or service name, Bash attempts to open a UDP connection to the corresponding socket. - @end table A failure to open or create a file causes the redirection to fail. @@ -2720,7 +2730,7 @@ parameter assignments are placed in the environment for a command, not just those that precede the command name. When Bash invokes an external command, the variable @samp{$_} -is set to the full path name of the command and passed to that +is set to the full pathname of the command and passed to that command in its environment. @node Exit Status @@ -2731,7 +2741,7 @@ The exit status of an executed command is the value returned by the @var{waitpid} system call or equivalent function. Exit statuses fall between 0 and 255, though, as explained below, the shell may use values above 125 specially. Exit statuses from shell builtins and -compound commands are also limited to this range. Under certain +compound commands are also limited to this range. Under certain circumstances, the shell will use special values to indicate specific failure modes. @@ -2924,6 +2934,7 @@ These commands are implemented as specified by the @sc{posix} standard. @example : [@var{arguments}] @end example + Do nothing beyond expanding @var{arguments} and performing redirections. The return status is zero. @@ -2932,6 +2943,7 @@ The return status is zero. @example . @var{filename} [@var{arguments}] @end example + Read and execute commands from the @var{filename} argument in the current shell context. If @var{filename} does not contain a slash, the @env{PATH} variable is used to find @var{filename}. @@ -2950,6 +2962,7 @@ This builtin is equivalent to @code{source}. @example break [@var{n}] @end example + Exit from a @code{for}, @code{while}, @code{until}, or @code{select} loop. If @var{n} is supplied, the @var{n}th enclosing loop is exited. @var{n} must be greater than or equal to 1. @@ -2960,6 +2973,7 @@ The return status is zero unless @var{n} is not greater than or equal to 1. @example cd [-L|[-P [-e]]] [@var{directory}] @end example + Change the current working directory to @var{directory}. If @var{directory} is not given, the value of the @env{HOME} shell variable is used. @@ -2988,6 +3002,7 @@ non-zero otherwise. @example continue [@var{n}] @end example + Resume the next iteration of an enclosing @code{for}, @code{while}, @code{until}, or @code{select} loop. If @var{n} is supplied, the execution of the @var{n}th enclosing loop @@ -3000,6 +3015,7 @@ The return status is zero unless @var{n} is not greater than or equal to 1. @example eval [@var{arguments}] @end example + The arguments are concatenated together into a single command, which is then read and executed, and its exit status returned as the exit status of @code{eval}. @@ -3011,6 +3027,7 @@ zero. @example exec [-cl] [-a @var{name}] [@var{command} [@var{arguments}]] @end example + If @var{command} is supplied, it replaces the shell without creating a new process. If the @option{-l} option is supplied, the shell places a dash at the @@ -3020,6 +3037,11 @@ The @option{-c} option causes @var{command} to be executed with an empty environment. If @option{-a} is supplied, the shell passes @var{name} as the zeroth argument to @var{command}. +If @var{command} +cannot be executed for some reason, a non-interactive shell exits, +unless the @code{execfail} shell option +is enabled. In that case, it returns failure. +An interactive shell returns failure if the file cannot be executed. If no @var{command} is specified, redirections may be used to affect the current shell environment. If there are no redirection errors, the return status is zero; otherwise the return status is non-zero. @@ -3029,6 +3051,7 @@ return status is zero; otherwise the return status is non-zero. @example exit [@var{n}] @end example + Exit the shell, returning a status of @var{n} to the shell's parent. If @var{n} is omitted, the exit status is that of the last command executed. Any trap on @code{EXIT} is executed before the shell terminates. @@ -3038,12 +3061,13 @@ Any trap on @code{EXIT} is executed before the shell terminates. @example export [-fn] [-p] [@var{name}[=@var{value}]] @end example + Mark each @var{name} to be passed to child processes in the environment. If the @option{-f} option is supplied, the @var{name}s refer to shell functions; otherwise the names refer to shell variables. The @option{-n} option means to no longer mark each @var{name} for export. If no @var{names} are supplied, or if the @option{-p} option is given, a -list of exported names is displayed. +list of names of all exported variables is displayed. The @option{-p} option displays output in a form that may be reused as input. If a variable name is followed by =@var{value}, the value of the variable is set to @var{value}. @@ -3057,10 +3081,11 @@ with a name that is not a shell function. @example getopts @var{optstring} @var{name} [@var{args}] @end example + @code{getopts} is used by shell scripts to parse positional parameters. @var{optstring} contains the option characters to be recognized; if a character is followed by a colon, the option is expected to have an -argument, which should be separated from it by white space. +argument, which should be separated from it by whitespace. The colon (@samp{:}) and question mark (@samp{?}) may not be used as option characters. Each time it is invoked, @code{getopts} @@ -3087,7 +3112,7 @@ given in @var{args}, @code{getopts} parses those instead. @code{getopts} can report errors in two ways. If the first character of @var{optstring} is a colon, @var{silent} -error reporting is used. In normal operation diagnostic messages +error reporting is used. In normal operation, diagnostic messages are printed when invalid options or missing option arguments are encountered. If the variable @env{OPTERR} @@ -3111,6 +3136,7 @@ If @code{getopts} is silent, then a colon (@samp{:}) is placed in @example hash [-r] [-p @var{filename}] [-dt] [@var{name}] @end example + Each time @code{hash} is invoked, it remembers the full pathnames of the commands specified as @var{name} arguments, so they need not be searched for on subsequent invocations. @@ -3138,6 +3164,7 @@ option is supplied. @example pwd [-LP] @end example + Print the absolute pathname of the current working directory. If the @option{-P} option is supplied, the pathname printed will not contain symbolic links. @@ -3152,6 +3179,7 @@ is supplied. @example readonly [-aAf] [-p] [@var{name}[=@var{value}]] @dots{} @end example + Mark each @var{name} as readonly. The values of these names may not be changed by subsequent assignment. If the @option{-f} option is supplied, each @var{name} refers to a shell @@ -3177,11 +3205,14 @@ or the @option{-f} option is supplied with a name that is not a shell function. @example return [@var{n}] @end example -Cause a shell function to exit with the return value @var{n}. + +Cause a shell function to stop executing and return the value @var{n} +to its caller. If @var{n} is not supplied, the return value is the exit status of the last command executed in the function. -This may also be used to terminate execution of a script being executed -with the @code{.} (or @code{source}) builtin, returning either @var{n} or +@code{return} may also be used to terminate execution of a script +being executed with the @code{.} (@code{source}) builtin, +returning either @var{n} or the exit status of the last command executed within the script as the exit status of the script. Any command associated with the @code{RETURN} trap is executed @@ -3194,6 +3225,7 @@ and not during the execution of a script by @code{.} or @code{source}. @example shift [@var{n}] @end example + Shift the positional parameters to the left by @var{n}. The positional parameters from @var{n}+1 @dots{} @code{$#} are renamed to @code{$1} @dots{} @code{$#}-@var{n}. @@ -3206,11 +3238,16 @@ If @var{n} is not supplied, it is assumed to be 1. The return status is zero unless @var{n} is greater than @code{$#} or less than zero, non-zero otherwise. -@item test +@item test[B @itemx [ @btindex test @btindex [ -Evaluate a conditional expression @var{expr}. +@example +test @var{expr} +@end example + +Evaluate a conditional expression @var{expr} and return a status of 0 +(true) or 1 (false). Each operator and operand must be a separate argument. Expressions are composed of the primaries described below in @ref{Bash Conditional Expressions}. @@ -3293,6 +3330,7 @@ operators sort lexicographically using ASCII ordering. @example times @end example + Print out the user and system times used by the shell and its children. The return status is zero. @@ -3301,6 +3339,7 @@ The return status is zero. @example trap [-lp] [@var{arg}] [@var{sigspec} @dots{}] @end example + The commands in @var{arg} are to be read and executed when the shell receives signal @var{sigspec}. If @var{arg} is absent (and there is a single @var{sigspec}) or @@ -3355,6 +3394,7 @@ valid signal. @example umask [-p] [-S] [@var{mode}] @end example + Set the shell process's file creation mask to @var{mode}. If @var{mode} begins with a digit, it is interpreted as an octal number; if not, it is interpreted as a symbolic mode mask similar @@ -3376,7 +3416,8 @@ results in permissions of @code{755}. @example unset [-fv] [@var{name}] @end example -Each variable or function @var{name} is removed. + +Remove each variable or function @var{name}. If the @option{-v} option is given, each @var{name} refers to a shell variable and that variable is remvoved. If the @option{-f} option is given, the @var{name}s refer to shell @@ -3400,7 +3441,7 @@ Some of these commands are specified in the @sc{posix} standard. @item alias @btindex alias @example -alias [@code{-p}] [@var{name}[=@var{value}] @dots{}] +alias [-p] [@var{name}[=@var{value}] @dots{}] @end example Without arguments or with the @option{-p} option, @code{alias} prints @@ -3507,6 +3548,7 @@ error occurs. @example builtin [@var{shell-builtin} [@var{args}]] @end example + Run a shell builtin, passing it @var{args}, and return its exit status. This is useful when defining a shell function with the same name as a shell builtin, retaining the functionality of the builtin within @@ -3519,6 +3561,7 @@ builtin command. @example caller [@var{expr}] @end example + Returns the context of any active subroutine call (a shell function or a script executed with the @code{.} or @code{source} builtins). @@ -3539,6 +3582,7 @@ call stack. @example command [-pVv] @var{command} [@var{arguments} @dots{}] @end example + Runs @var{command} with @var{arguments} ignoring any shell function named @var{command}. Only shell builtin commands or commands found by searching the @@ -3562,7 +3606,7 @@ zero if @var{command} is found, and non-zero if not. @item declare @btindex declare @example -declare [-aAfFilrtux] [-p] [@var{name}[=@var{value}] @dots{}] +declare [-aAfFgilrtux] [-p] [@var{name}[=@var{value}] @dots{}] @end example Declare variables and give them attributes. If no @var{name}s @@ -3639,7 +3683,7 @@ with the exceptions that @samp{+a} may not be used to destroy an array variable and @samp{+r} will not remove the readonly attribute. When used in a function, @code{declare} makes each @var{name} local, -as with the @code{local} command, unless the @samp{-g} option is used. +as with the @code{local} command, unless the @option{-g} option is used. If a variable name is followed by =@var{value}, the value of the variable is set to @var{value}. @@ -3658,6 +3702,7 @@ or an attempt is made to display a non-existent function with @option{-f}. @example echo [-neE] [@var{arg} @dots{}] @end example + Output the @var{arg}s, separated by spaces, terminated with a newline. The return status is 0 unless a write error occurs. @@ -3713,6 +3758,7 @@ the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value @example enable [-a] [-dnps] [-f @var{filename}] [@var{name} @dots{}] @end example + Enable and disable builtin shell commands. Disabling a builtin allows a disk command which has the same name as a shell builtin to be executed without specifying a full pathname, @@ -3745,6 +3791,7 @@ or there is an error loading a new builtin from a shared object. @example help [-dms] [@var{pattern}] @end example + Display helpful information about builtin commands. If @var{pattern} is specified, @code{help} gives detailed help on all commands matching @var{pattern}, otherwise a list of @@ -3766,8 +3813,9 @@ The return status is zero unless no command matches @var{pattern}. @item let @btindex let @example -let @var{expression} [@var{expression}] +let @var{expression} [@var{expression} @dots{}] @end example + The @code{let} builtin allows arithmetic to be performed on shell variables. Each @var{expression} is evaluated according to the rules given below in @ref{Shell Arithmetic}. If the @@ -3779,6 +3827,7 @@ otherwise 0 is returned. @example local [@var{option}] @var{name}[=@var{value}] @dots{} @end example + For each argument, a local variable named @var{name} is created, and assigned @var{value}. The @var{option} can be any of the options accepted by @code{declare}. @@ -3793,20 +3842,23 @@ readonly variable. @example logout [@var{n}] @end example + Exit a login shell, returning a status of @var{n} to the shell's parent. @item mapfile @btindex mapfile @example -mapfile [-n @var{count}] [-O @var{origin}] [-s @var{count}] [-t] [-u @var{fd}] [ --C @var{callback}] [-c @var{quantum}] [@var{array}] +mapfile [-n @var{count}] [-O @var{origin}] [-s @var{count}] [-t] [-u @var{fd}] + [-C @var{callback}] [-c @var{quantum}] [@var{array}] @end example + Read lines from the standard input into the indexed array variable @var{array}, or from file descriptor @var{fd} if the @option{-u} option is supplied. The variable @code{MAPFILE} is the default @var{array}. Options, if supplied, have the following meanings: + @table @code @item -n @@ -3847,6 +3899,7 @@ is not an indexed array. @example printf [-v @var{var}] @var{format} [@var{arguments}] @end example + Write the formatted @var{arguments} to the standard output under the control of the @var{format}. The @option{-v} option causes the output to be assigned to the variable @@ -3862,16 +3915,16 @@ interprets the following extensions: @table @code @item %b -causes @code{printf} to expand backslash escape sequences in the +Causes @code{printf} to expand backslash escape sequences in the corresponding @var{argument}, -(except that @samp{\c} terminates output, backslashes in +except that @samp{\c} terminates output, backslashes in @samp{\'}, @samp{\"}, and @samp{\?} are not removed, and octal escapes -beginning with @samp{\0} may contain up to four digits). +beginning with @samp{\0} may contain up to four digits. @item %q -causes @code{printf} to output the +Causes @code{printf} to output the corresponding @var{argument} in a format that can be reused as shell input. @item %(@var{datefmt})T -causes @code{printf} to output the date-time string resulting from using +Causes @code{printf} to output the date-time string resulting from using @var{datefmt} as a format string for @code{strftime}(3). The corresponding @var{argument} is an integer representing the number of seconds since the epoch. Two special argument values may be used: -1 represents the current @@ -3893,8 +3946,10 @@ non-zero on failure. @item read @btindex read @example -read [-ers] [-a @var{aname}] [-d @var{delim}] [-i @var{text}] [-n @var{nchars}] [-N @var{nchars}] [-p @var{prompt}] [-t @var{timeout}] [-u @var{fd}] [@var{name} @dots{}] +read [-ers] [-a @var{aname}] [-d @var{delim}] [-i @var{text}] [-n @var{nchars}] + [-N @var{nchars}] [-p @var{prompt}] [-t @var{timeout}] [-u @var{fd}] [@var{name} @dots{}] @end example + One line is read from the standard input, or from the file descriptor @var{fd} supplied as an argument to the @option{-u} option, and the first word is assigned to the first @var{name}, the second word to the second @var{name}, @@ -3977,15 +4032,15 @@ The exit status is greater than 128 if the timeout is exceeded. @item -u @var{fd} Read input from file descriptor @var{fd}. - @end table @item readarray @btindex readarray @example -readarray [-n @var{count}] [-O @var{origin}] [-s @var{count}] [-t] [-u @var{fd}] [ --C @var{callback}] [-c @var{quantum}] [@var{array}] +readarray [-n @var{count}] [-O @var{origin}] [-s @var{count}] [-t] [-u @var{fd}] + [-C @var{callback}] [-c @var{quantum}] [@var{array}] @end example + Read lines from the standard input into the indexed array variable @var{array}, or from file descriptor @var{fd} if the @option{-u} option is supplied. @@ -3997,6 +4052,7 @@ A synonym for @code{mapfile}. @example source @var{filename} @end example + A synonym for @code{.} (@pxref{Bourne Shell Builtins}). @item type @@ -4004,6 +4060,7 @@ A synonym for @code{.} (@pxref{Bourne Shell Builtins}). @example type [-afptP] [@var{name} @dots{}] @end example + For each @var{name}, indicate how it would be interpreted if used as a command name. @@ -4023,7 +4080,7 @@ The @option{-P} option forces a path search for each @var{name}, even if @option{-t} would not return @samp{file}. If a command is hashed, @option{-p} and @option{-P} print the hashed value, -not necessarily the file that appears first in @code{$PATH}. +which is not necessarily the file that appears first in @code{$PATH}. If the @option{-a} option is used, @code{type} returns all of the places that contain an executable named @var{file}. @@ -4039,20 +4096,23 @@ if any are not found. @item typeset @btindex typeset @example -typeset [-afFrxi] [-p] [@var{name}[=@var{value}] @dots{}] +typeset [-afFgrxilrtux] [-p] [@var{name}[=@var{value}] @dots{}] @end example + The @code{typeset} command is supplied for compatibility with the Korn -shell; however, it has been deprecated in favor of the @code{declare} -builtin command. +shell. +It is a synonym for the @code{declare} builtin command. @item ulimit @btindex ulimit @example ulimit [-abcdefilmnpqrstuvxHST] [@var{limit}] @end example + @code{ulimit} provides control over the resources available to processes started by the shell, on systems that allow such control. If an option is given, it is interpreted as follows: + @table @code @item -S Change and report the soft limit associated with a resource. @@ -4118,11 +4178,11 @@ The maximum number of file locks. @item -T The maximum number of threads. - @end table -If @var{limit} is given, it is the new value of the specified resource; -the special @var{limit} values @code{hard}, @code{soft}, and +If @var{limit} is given, and the @option{-a} option is not used, +@var{limit} is the new value of the specified resource. +The special @var{limit} values @code{hard}, @code{soft}, and @code{unlimited} stand for the current hard limit, the current soft limit, and no limit, respectively. A hard limit cannot be increased by a non-root user once it is set; @@ -4132,9 +4192,9 @@ is printed, unless the @option{-H} option is supplied. When setting new limits, if neither @option{-H} nor @option{-S} is supplied, both the hard and soft limits are set. If no option is given, then @option{-f} is assumed. Values are in 1024-byte -increments, except for @option{-t}, which is in seconds, @option{-p}, -which is in units of 512-byte blocks, and @option{-n} and @option{-u}, which -are unscaled values. +increments, except for @option{-t}, which is in seconds; @option{-p}, +which is in units of 512-byte blocks; and @option{-T}, @option{-b}, +@option{-n} and @option{-u}, which are unscaled values. The return status is zero unless an invalid option or argument is supplied, or an error occurs while setting a new limit. @@ -4148,7 +4208,6 @@ unalias [-a] [@var{name} @dots{} ] Remove each @var{name} from the list of aliases. If @option{-a} is supplied, all aliases are removed. Aliases are described in @ref{Aliases}. - @end table @node Modifying Shell Behavior @@ -4341,9 +4400,9 @@ processed, shell functions are not inherited from the environment, and the @env{SHELLOPTS}, @env{BASHOPTS}, @env{CDPATH} and @env{GLOBIGNORE} variables, if they appear in the environment, are ignored. If the shell is started with the effective user (group) id not equal to the -real user (group) id, and the @code{-p} option is not supplied, these actions +real user (group) id, and the @option{-p} option is not supplied, these actions are taken and the effective user id is set to the real user id. -If the @code{-p} option is supplied at startup, the effective user id is +If the @option{-p} option is supplied at startup, the effective user id is not reset. Turning this option off causes the effective user and group ids to be set to the real user and group ids. @@ -4452,6 +4511,7 @@ This builtin allows you to change additional shell optional behavior. @example shopt [-pqsu] [-o] [@var{optname} @dots{}] @end example + Toggle the values of variables controlling optional shell behavior. With no options, or with the @option{-p} option, a list of all settable options is displayed, with an indication of whether or not each is set. @@ -4480,7 +4540,7 @@ Restricts the values of @end table If either @option{-s} or @option{-u} -is used with no @var{optname} arguments, the display is limited to +is used with no @var{optname} arguments, @code{shopt} shows only those options which are set or unset, respectively. Unless otherwise noted, the @code{shopt} options are disabled (off) @@ -4757,7 +4817,7 @@ This option is enabled by default. If set, prompt strings undergo parameter expansion, command substitution, arithmetic expansion, and quote removal after being expanded -as described below (@pxref{Printing a Prompt}). +as described below (@pxref{Controlling the Prompt}). This option is enabled by default. @item restricted_shell @@ -4788,7 +4848,6 @@ The return status when listing options is zero if all @var{optnames} are enabled, non-zero otherwise. When setting or unsetting options, the return status is zero unless an @var{optname} is not a valid shell option. - @end table @node Special Builtins @@ -4866,7 +4925,7 @@ the specified file or Maildir-format directory. A colon-separated list of filenames which the shell periodically checks for new mail. Each list entry can specify the message that is printed when new mail -arrives in the mail file by separating the file name from the message with +arrives in the mail file by separating the filename from the message with a @samp{?}. When used in the text of the message, @code{$_} expands to the name of the current mail file. @@ -4888,7 +4947,7 @@ or trailing colon. @item PS1 The primary prompt string. The default value is @samp{\s-\v\$ }. -@xref{Printing a Prompt}, for the complete list of escape +@xref{Controlling the Prompt}, for the complete list of escape sequences that are expanded before @env{PS1} is displayed. @item PS2 @@ -5031,7 +5090,6 @@ The release status (e.g., @var{beta1}). @item BASH_VERSINFO[5] The value of @env{MACHTYPE}. - @end table @item BASH_VERSION @@ -5149,9 +5207,9 @@ builtin command. @item FIGNORE A colon-separated list of suffixes to ignore when performing filename completion. -A file name whose suffix matches one of the entries in +A filename whose suffix matches one of the entries in @env{FIGNORE} -is excluded from the list of matched file names. A sample +is excluded from the list of matched filenames. A sample value is @samp{.o:~} @item FUNCNAME @@ -5380,10 +5438,10 @@ in the most-recently-executed foreground pipeline (which may contain only a single command). @item POSIXLY_CORRECT -If this variable is in the environment when @code{bash} starts, the shell +If this variable is in the environment when Bash starts, the shell enters @sc{posix} mode (@pxref{Bash POSIX Mode}) before reading the startup files, as if the @option{--posix} invocation option had been supplied. -If it is set while the shell is running, @code{bash} enables @sc{posix} mode, +If it is set while the shell is running, Bash enables @sc{posix} mode, as if the command @example @code{set -o posix} @@ -5402,7 +5460,7 @@ before the printing of each primary prompt (@env{$PS1}). @item PROMPT_DIRTRIM If set to a number greater than zero, the value is used as the number of trailing directory components to retain when expanding the @code{\w} and -@code{\W} prompt string escapes (@pxref{Printing a Prompt}). +@code{\W} prompt string escapes (@pxref{Controlling the Prompt}). Characters removed are replaced with an ellipsis. @item PS3 @@ -5533,7 +5591,7 @@ The numeric real user id of the current user. This variable is readonly. @node Bash Features @chapter Bash Features -This section describes features unique to Bash. +This chapter describes features unique to Bash. @menu * Invoking Bash:: Command line options that you can give @@ -5546,7 +5604,7 @@ This section describes features unique to Bash. * Aliases:: Substituting one command for another. * Arrays:: Array Variables. * The Directory Stack:: History of visited directories. -* Printing a Prompt:: Controlling the PS1 string. +* Controlling the Prompt:: Customizing the various prompt strings. * The Restricted Shell:: A more controlled mode of shell execution. * Bash POSIX Mode:: Making Bash behave more closely to what the POSIX standard specifies. @@ -5625,7 +5683,6 @@ Equivalent to @option{-v}. Print shell input lines as they're read. @item --version Show version information for this instance of Bash on the standard output and exit successfully. - @end table There are several single-character options that may be supplied at @@ -5683,7 +5740,6 @@ that may be reused as input. A @code{--} signals the end of options and disables further option processing. Any arguments after the @code{--} are treated as filenames and arguments. - @end table @cindex login shell @@ -5715,7 +5771,7 @@ in the script. If no commands are executed, the exit status is 0. This section describes how Bash executes its startup files. If any of the files exist but cannot be read, Bash reports an error. -Tildes are expanded in file names as described above under +Tildes are expanded in filenames as described above under Tilde Expansion (@pxref{Tilde Expansion}). Interactive shells are described in @ref{Interactive Shells}. @@ -5761,7 +5817,7 @@ following command were executed: @end example @noindent but the value of the @env{PATH} variable is not used to search for the -file name. +filename. As noted above, if a non-interactive shell is invoked with the @option{--login} option, Bash attempts to read and execute commands from the @@ -5817,12 +5873,12 @@ allow them to be specified. @subsubheading Invoked with unequal effective and real @sc{uid/gid}s If Bash is started with the effective user (group) id not equal to the -real user (group) id, and the @code{-p} option is not supplied, no startup +real user (group) id, and the @option{-p} option is not supplied, no startup files are read, shell functions are not inherited from the environment, the @env{SHELLOPTS}, @env{BASHOPTS}, @env{CDPATH}, and @env{GLOBIGNORE} variables, if they appear in the environment, are ignored, and the effective user id is set to the real user id. -If the @code{-p} option is supplied at invocation, the startup behavior is +If the @option{-p} option is supplied at invocation, the startup behavior is the same, but the effective user id is not reset. @node Interactive Shells @@ -6118,7 +6174,6 @@ is equal to, not equal to, less than, less than or equal to, greater than, or greater than or equal to @var{arg2}, respectively. @var{Arg1} and @var{arg2} may be positive or negative integers. - @end table @node Shell Arithmetic @@ -6249,8 +6304,9 @@ aliases, but a word that is identical to an alias being expanded is not expanded a second time. This means that one may alias @code{ls} to @code{"ls -F"}, for instance, and Bash does not try to recursively expand the -replacement text. If the last character of the alias value is a -space or tab character, then the next command word following the +replacement text. +If the last character of the alias value is a +@var{blank}, then the next command word following the alias is also checked for alias expansion. Aliases are created and listed with the @code{alias} @@ -6303,7 +6359,7 @@ associative arrays use arbitrary strings. An indexed array is created automatically if any variable is assigned to using the syntax @example -name[@var{subscript}]=@var{value} +@var{name}[@var{subscript}]=@var{value} @end example @noindent @@ -6321,6 +6377,7 @@ declare -a @var{name}[@var{subscript}] @noindent is also accepted; the @var{subscript} is ignored. +@noindent Associative arrays are created using @example declare -A @var{name}. @@ -6333,12 +6390,12 @@ an array. Arrays are assigned to using compound assignments of the form @example -name=(value@var{1} @dots{} value@var{n}) +@var{name}=(@var{value1} @var{value2} @dots{} ) @end example @noindent where each @var{value} is of the form @code{[@var{subscript}]=}@var{string}. -Indexed array assignments do not require the bracket and subscript. +Indexed array assignments do not require anything but @var{string}. When assigning to indexed arrays, if the optional subscript is supplied, that index is assigned to; otherwise the index of the element assigned is the last index assigned @@ -6348,29 +6405,29 @@ When assigning to an associative array, the subscript is required. This syntax is also accepted by the @code{declare} builtin. Individual array elements may be assigned to using the -@code{name[}@var{subscript}@code{]=}@var{value} syntax introduced above. +@code{@var{name}[@var{subscript}]=@var{value}} syntax introduced above. Any element of an array may be referenced using -@code{$@{name[}@var{subscript}@code{]@}}. +@code{$@{@var{name}[@var{subscript}]@}}. The braces are required to avoid conflicts with the shell's filename expansion operators. If the @var{subscript} is @samp{@@} or @samp{*}, the word expands to all members of the array @var{name}. These subscripts differ only when the word appears within double quotes. If the word is double-quoted, -@code{$@{name[*]@}} expands to a single word with +@code{$@{@var{name}[*]@}} expands to a single word with the value of each array member separated by the first character of the -@env{IFS} variable, and @code{$@{name[@@]@}} expands each element of +@env{IFS} variable, and @code{$@{@var{name}[@@]@}} expands each element of @var{name} to a separate word. When there are no array members, -@code{$@{name[@@]@}} expands to nothing. +@code{$@{@var{name}[@@]@}} expands to nothing. If the double-quoted expansion occurs within a word, the expansion of the first parameter is joined with the beginning part of the original word, and the expansion of the last parameter is joined with the last part of the original word. This is analogous to the expansion of the special parameters @samp{@@} and @samp{*}. -@code{$@{#name[}@var{subscript}@code{]@}} expands to the length of -@code{$@{name[}@var{subscript}@code{]@}}. +@code{$@{#@var{name}[@var{subscript}]@}} expands to the length of +@code{$@{@var{name}[@var{subscript}]@}}. If @var{subscript} is @samp{@@} or @samp{*}, the expansion is the number of elements in the array. Referencing an array variable without a subscript is equivalent to @@ -6385,12 +6442,12 @@ An array variable is considered set if a subscript has been assigned a value. The null string is a valid value. The @code{unset} builtin is used to destroy arrays. -@code{unset} @var{name}[@var{subscript}] +@code{unset @var{name}[@var{subscript}]} destroys the array element at index @var{subscript}. Care must be taken to avoid unwanted side effects caused by filename expansion. -@code{unset} @var{name}, where @var{name} is an array, removes the -entire array. A subscript of @samp{*} or @samp{@@} also removes the +@code{unset @var{name}}, where @var{name} is an array, removes the +entire array. A subscript of @samp{*} or @samp{@@} also removes the entire array. The @code{declare}, @code{local}, and @code{readonly} @@ -6431,37 +6488,39 @@ as the value of the @env{DIRSTACK} shell variable. @item dirs @btindex dirs @example -dirs [+@var{N} | -@var{N}] [-clpv] +dirs [-clpv] [+@var{N} | -@var{N}] @end example + Display the list of currently remembered directories. Directories are added to the list with the @code{pushd} command; the @code{popd} command removes directories from the list. + @table @code -@item +@var{N} -Displays the @var{N}th directory (counting from the left of the -list printed by @code{dirs} when invoked without options), starting -with zero. -@item -@var{N} -Displays the @var{N}th directory (counting from the right of the -list printed by @code{dirs} when invoked without options), starting -with zero. @item -c Clears the directory stack by deleting all of the elements. @item -l -Produces a longer listing; the default listing format uses a -tilde to denote the home directory. +Produces a listing using full pathnames; +the default listing format uses a tilde to denote the home directory. @item -p Causes @code{dirs} to print the directory stack with one entry per line. @item -v Causes @code{dirs} to print the directory stack with one entry per line, prefixing each entry with its index in the stack. +@item +@var{N} +Displays the @var{N}th directory (counting from the left of the +list printed by @code{dirs} when invoked without options), starting +with zero. +@item -@var{N} +Displays the @var{N}th directory (counting from the right of the +list printed by @code{dirs} when invoked without options), starting +with zero. @end table @item popd @btindex popd @example -popd [+@var{N} | -@var{N}] [-n] +popd [-n] [+@var{N} | -@var{N}] @end example Remove the top entry from the directory stack, and @code{cd} @@ -6470,23 +6529,24 @@ When no arguments are given, @code{popd} removes the top directory from the stack and performs a @code{cd} to the new top directory. The elements are numbered from 0 starting at the first directory listed with -@code{dirs}; i.e., @code{popd} is equivalent to @code{popd +0}. +@code{dirs}; that is, @code{popd} is equivalent to @code{popd +0}. + @table @code +@item -n +Suppresses the normal change of directory when removing directories +from the stack, so that only the stack is manipulated. @item +@var{N} Removes the @var{N}th directory (counting from the left of the list printed by @code{dirs}), starting with zero. @item -@var{N} Removes the @var{N}th directory (counting from the right of the list printed by @code{dirs}), starting with zero. -@item -n -Suppresses the normal change of directory when removing directories -from the stack, so that only the stack is manipulated. @end table @btindex pushd @item pushd @example -pushd [-n] [@var{+N} | @var{-N} | @var{dir} ] +pushd [-n] [@var{+N} | @var{-N} | @var{dir}] @end example Save the current directory on the top of the directory stack @@ -6506,14 +6566,13 @@ Brings the @var{N}th directory (counting from the right of the list printed by @code{dirs}, starting with zero) to the top of the list by rotating the stack. @item @var{dir} -Makes the current working directory be the top of the stack, and then -executes the equivalent of `@code{cd} @var{dir}'. -@code{cd}s to @var{dir}. +Makes the current working directory be the top of the stack, making +it the new current directory as if it had been supplied as an argument +to the @code{cd} builtin. @end table - @end table -@node Printing a Prompt +@node Controlling the Prompt @section Controlling the Prompt @cindex prompting @@ -6523,7 +6582,7 @@ has a non-null value, then the value is executed just as if it had been typed on the command line. In addition, the following table describes the special characters which -can appear in the prompt variables: +can appear in the prompt variables @env{PS1} to @env{PS4}: @table @code @item \a @@ -6750,6 +6809,10 @@ contain characters other than letters, digits, and underscores, and may not start with a digit. Declaring a function with an invalid name causes a fatal syntax error in non-interactive shells. +@item +Function names may not be the same as one of the @sc{posix} special +builtins. + @item @sc{posix} special builtins are found before shell functions during command lookup. @@ -7010,7 +7073,7 @@ previous job with a @samp{-}. A job may also be referred to using a prefix of the name used to start it, or using a substring that appears in its command line. For example, @samp{%ce} refers -to a stopped @code{ce} job. Using @samp{%?ce}, on the +to a stopped @code{ce} job. Using @samp{%?ce}, on the other hand, refers to any job containing the string @samp{ce} in its command line. If the prefix or substring matches more than one job, Bash reports an error. @@ -7047,6 +7110,7 @@ Bash does not print another warning, and any stopped jobs are terminated. @example bg [@var{jobspec} @dots{}] @end example + Resume each suspended job @var{jobspec} in the background, as if it had been started with @samp{&}. If @var{jobspec} is not supplied, the current job is used. @@ -7060,6 +7124,7 @@ that was started without job control. @example fg [@var{jobspec}] @end example + Resume the job @var{jobspec} in the foreground and make it the current job. If @var{jobspec} is not supplied, the current job is used. The return status is that of the command placed into the foreground, @@ -7089,10 +7154,10 @@ the user was last notified of their status. List only the process @sc{id} of the job's process group leader. @item -r -Restrict output to running jobs. +Display only running jobs. @item -s -Restrict output to stopped jobs. +Display only stopped jobs. @end table If @var{jobspec} is given, @@ -7111,6 +7176,7 @@ passing it @var{argument}s, returning its exit status. kill [-s @var{sigspec}] [-n @var{signum}] [-@var{sigspec}] @var{jobspec} or @var{pid} kill -l [@var{exit_status}] @end example + Send a signal specified by @var{sigspec} or @var{signum} to the process named by job specification @var{jobspec} or process @sc{id} @var{pid}. @var{sigspec} is either a case-insensitive signal name such as @@ -7129,8 +7195,9 @@ or non-zero if an error occurs or an invalid option is encountered. @item wait @btindex wait @example -wait [@var{jobspec} or @var{pid} ...] +wait [@var{jobspec} or @var{pid} @dots{}] @end example + Wait until the child process specified by each process @sc{id} @var{pid} or job specification @var{jobspec} exits and return the exit status of the last command waited for. @@ -7145,7 +7212,8 @@ of the shell, the return status is 127. @example disown [-ar] [-h] [@var{jobspec} @dots{}] @end example -Without options, each @var{jobspec} is removed from the table of + +Without options, remove each @var{jobspec} from the table of active jobs. If the @option{-h} option is given, the job is not removed from the table, but is marked so that @code{SIGHUP} is not sent to the job if the shell @@ -7161,11 +7229,11 @@ argument restricts operation to running jobs. @example suspend [-f] @end example + Suspend the execution of this shell until it receives a @code{SIGCONT} signal. A login shell cannot be suspended; the @option{-f} option can be used to override this and force the suspension. - @end table When job control is not active, the @code{kill} and @code{wait} @@ -7648,7 +7716,7 @@ If Readline is not enabled, this option has no effect. @item --enable-prompt-string-decoding Turn on the interpretation of a number of backslash-escaped characters in the @env{$PS1}, @env{$PS2}, @env{$PS3}, and @env{$PS4} prompt -strings. See @ref{Printing a Prompt}, for a complete list of prompt +strings. See @ref{Controlling the Prompt}, for a complete list of prompt string escape sequences. @item --enable-readline @@ -7688,7 +7756,6 @@ which makes the Bash @code{echo} behave more like the version specified in the Single Unix Specification, version 3. @xref{Bash Builtins}, for a description of the escape sequences that @code{echo} recognizes. - @end table The file @file{config-top.h} contains C Preprocessor @@ -8044,7 +8111,7 @@ Bash has much more optional behavior controllable with the @code{set} builtin (@pxref{The Set Builtin}). @item -The @samp{-x} (@code{xtrace}) option displays commands other than +The @samp{-x} (@option{xtrace}) option displays commands other than simple commands when performing an execution trace (@pxref{The Set Builtin}). @@ -8107,7 +8174,7 @@ Bash also makes the directory stack visible as the value of the @item Bash interprets special backslash-escaped characters in the prompt -strings when interactive (@pxref{Printing a Prompt}). +strings when interactive (@pxref{Controlling the Prompt}). @item The Bash restricted mode is more useful (@pxref{The Restricted Shell}); diff --git a/doc/bashref.texi~ b/doc/bashref.texi~ index 825287217..f5c83d5d4 100644 --- a/doc/bashref.texi~ +++ b/doc/bashref.texi~ @@ -85,7 +85,7 @@ Bash contains features that appear in other popular shells, and some features that only appear in Bash. Some of the shells that Bash has borrowed concepts from are the Bourne Shell (@file{sh}), the Korn Shell (@file{ksh}), and the C-shell (@file{csh} and its successor, -@file{tcsh}). The following menu breaks the features up into +@file{tcsh}). The following menu breaks the features up into categories based upon which one of these other shells inspired the feature. @@ -627,7 +627,7 @@ the control operators @samp{|} or @samp{|&}. @cindex command timing The format for a pipeline is @example -[@code{time} [@code{-p}]] [@code{!}] @var{command1} [ [@code{|} or @code{|&}] @var{command2} @dots{}] +[time [-p]] [!] @var{command1} [ | or |& @var{command2} ] @dots{} @end example @noindent @@ -637,9 +637,11 @@ That is, each command reads the previous command's output. This connection is performed before any redirections specified by the command. -If @samp{|&} is used, the standard error of @var{command1} is connected to -@var{command2}'s standard input through the pipe; it is shorthand for -@code{2>&1 |}. This implicit redirection of the standard error is +If @samp{|&} is used, @var{command1}'s standard output and standard error +are connected to +@var{command2}'s standard input through the pipe; +it is shorthand for @code{2>&1 |}. +This implicit redirection of the standard error is performed after any redirections specified by the command. The reserved word @code{time} causes timing statistics @@ -775,9 +777,11 @@ command's syntax, it may be replaced with one or more newlines. @rwindex do @rwindex done The syntax of the @code{until} command is: + @example until @var{test-commands}; do @var{consequent-commands}; done @end example + Execute @var{consequent-commands} as long as @var{test-commands} has an exit status which is not zero. The return status is the exit status of the last command executed @@ -786,6 +790,7 @@ in @var{consequent-commands}, or zero if none was executed. @item while @rwindex while The syntax of the @code{while} command is: + @example while @var{test-commands}; do @var{consequent-commands}; done @end example @@ -802,6 +807,7 @@ The syntax of the @code{for} command is: @example for @var{name} [ [in [@var{words} @dots{}] ] ; ] do @var{commands}; done @end example + Expand @var{words}, and execute @var{commands} once for each member in the resultant list, with @var{name} bound to the current member. If @samp{in @var{words}} is not present, the @code{for} command @@ -817,6 +823,7 @@ An alternate form of the @code{for} command is also supported: @example for (( @var{expr1} ; @var{expr2} ; @var{expr3} )) ; do @var{commands} ; done @end example + First, the arithmetic expression @var{expr1} is evaluated according to the rules described below (@pxref{Shell Arithmetic}). The arithmetic expression @var{expr2} is then evaluated repeatedly @@ -826,7 +833,6 @@ executed and the arithmetic expression @var{expr3} is evaluated. If any expression is omitted, it behaves as if it evaluates to 1. The return value is the exit status of the last command in @var{commands} that is executed, or false if any of the expressions is invalid. - @end table The @code{break} and @code{continue} builtins (@pxref{Bourne Shell Builtins}) @@ -873,7 +879,7 @@ zero if no condition tested true. The syntax of the @code{case} command is: @example -@code{case @var{word} in [ [(] @var{pattern} [| @var{pattern}]@dots{}) @var{command-list} ;;]@dots{} esac} +case @var{word} in [ [(] @var{pattern} [| @var{pattern}]@dots{}) @var{command-list} ;;]@dots{} esac @end example @code{case} will selectively execute the @var{command-list} corresponding to @@ -1052,11 +1058,11 @@ True if both @var{expression1} and @var{expression2} are true. @item @var{expression1} || @var{expression2} True if either @var{expression1} or @var{expression2} is true. @end table + @noindent -The @code{&&} and @code{||} operators do not evaluate @var{expression2} if the +The @code{&&} and @code{||} operators do not evaluate @var{[Bexpression2} if the value of @var{expression1} is sufficient to determine the return value of the entire conditional expression. - @end table @node Command Grouping @@ -1115,7 +1121,7 @@ established between the executing shell and the coprocess. The format for a coprocess is: @example -@code{coproc} [@var{NAME}] @var{command} [@var{redirections}] +coproc [@var{NAME}] @var{command} [@var{redirections}] @end example @noindent @@ -1125,22 +1131,22 @@ If @var{NAME} is not supplied, the default name is @var{COPROC}. command (@pxref{Simple Commands}); otherwise, it is interpreted as the first word of the simple command. -When the coproc is executed, the shell creates an array variable +When the coprocess is executed, the shell creates an array variable (@pxref{Arrays}) -named @var{NAME} in the context of the executing shell. +named @env{NAME} in the context of the executing shell. The standard output of @var{command} is connected via a pipe to a file descriptor in the executing shell, -and that file descriptor is assigned to @var{NAME}[0]. +and that file descriptor is assigned to @env{NAME}[0]. The standard input of @var{command} is connected via a pipe to a file descriptor in the executing shell, -and that file descriptor is assigned to @var{NAME}[1]. +and that file descriptor is assigned to @env{NAME}[1]. This pipe is established before any redirections specified by the command (@pxref{Redirections}). The file descriptors can be utilized as arguments to shell commands and redirections using standard word expansions. The process ID of the shell spawned to execute the coprocess is -available as the value of the variable @var{NAME}_PID. +available as the value of the variable @env{NAME}_PID. The @code{wait} builtin command may be used to wait for the coprocess to terminate. @@ -1237,8 +1243,13 @@ shell context; no new process is created to interpret them. Functions are declared using this syntax: @rwindex function @example -@var{name} () @var{compound-command} [ @var{redirections} ]@*or@* -@code{function} @var{name} [()] @var{compound-command} [ @var{redirections} ] +@var{name} () @var{compound-command} [ @var{redirections} ] +@end example + +or + +@example +function @var{name} [()] @var{compound-command} [ @var{redirections} ] @end example This defines a shell function named @var{name}. The reserved @@ -1318,8 +1329,8 @@ Variables local to the function may be declared with the the function and the commands it invokes. Function names and definitions may be listed with the -@option{-f} option to the @code{declare} or @code{typeset} -builtin commands (@pxref{Bash Builtins}). +@option{-f} option to the @code{declare} (@code{typeset}) +builtin command (@pxref{Bash Builtins}). The @option{-F} option to @code{declare} or @code{typeset} will list the function names only (and optionally the source file and line number, if the @code{extdebug} @@ -1505,6 +1516,7 @@ When checking mail, this parameter holds the name of the mail file. Expansion is performed on the command line after it has been split into @code{token}s. There are seven kinds of expansion performed: + @itemize @bullet @item brace expansion @item tilde expansion @@ -1559,7 +1571,7 @@ is performed. Brace expansion is a mechanism by which arbitrary strings may be generated. This mechanism is similar to @var{filename expansion} (@pxref{Filename Expansion}), -but the file names generated need not exist. +but the filenames generated need not exist. Patterns to be brace expanded take the form of an optional @var{preamble}, followed by either a series of comma-separated strings or a sequence expression between a pair of braces, @@ -1659,7 +1671,7 @@ left unchanged. Each variable assignment is checked for unquoted tilde-prefixes immediately following a @samp{:} or the first @samp{=}. In these cases, tilde expansion is also performed. -Consequently, one may use file names with tildes in assignments to +Consequently, one may use filenames with tildes in assignments to @env{PATH}, @env{MAILPATH}, and @env{CDPATH}, and the shell assigns the expanded value. @@ -1689,7 +1701,6 @@ The string that would be displayed by @samp{dirs +@var{N}} @item ~-@var{N} The string that would be displayed by @samp{dirs -@var{N}} - @end table @node Shell Parameter Expansion @@ -1903,7 +1914,6 @@ If @var{parameter} is an array variable subscripted with @samp{@@} or @samp{*}, the case modification operation is applied to each member of the array in turn, and the expansion is the resultant list. - @end table @node Command Substitution @@ -2051,8 +2061,8 @@ After word splitting, unless the @option{-f} option has been set If one of these characters appears, then the word is regarded as a @var{pattern}, and replaced with an alphabetically sorted list of -file names matching the pattern (@pxref{Pattern Matching}). -If no matching file names are found, +filenames matching the pattern (@pxref{Pattern Matching}). +If no matching filenames are found, and the shell option @code{nullglob} is disabled, the word is left unchanged. If the @code{nullglob} option is set, and no matches are found, the word @@ -2065,7 +2075,7 @@ without regard to the case of alphabetic characters. When a pattern is used for filename expansion, the character @samp{.} at the start of a filename or immediately following a slash must be matched explicitly, unless the shell option @code{dotglob} is set. -When matching a file name, the slash character must always be +When matching a filename, the slash character must always be matched explicitly. In other cases, the @samp{.} character is not treated specially. @@ -2268,7 +2278,6 @@ connection to the corresponding socket. If @var{host} is a valid hostname or Internet address, and @var{port} is an integer port number or service name, Bash attempts to open a UDP connection to the corresponding socket. - @end table A failure to open or create a file causes the redirection to fail. @@ -2380,8 +2389,8 @@ The format of here-documents is: @var{delimiter} @end example -No parameter expansion, command substitution, arithmetic expansion, -or filename expansion is performed on +No parameter and variable expansion, command substitution, +arithmetic expansion, or filename expansion is performed on @var{word}. If any characters in @var{word} are quoted, the @var{delimiter} is the result of quote removal on @var{word}, and the lines in the here-document are not expanded. @@ -2404,10 +2413,12 @@ A variant of here documents, the format is: <<< @var{word} @end example -The @var{word} -is expanded as described above, with the exception that -pathname expansion is not applied, and supplied as a single string -to the command on its standard input. +The @var{word} undergoes +brace expansion, tilde expansion, parameter and variable expansion, +command substitution, arithmetic expansion, and quote removal. +Pathname expansion word splitting are not performed. +The result is supplied as a single string to the command on its +standard input. @subsection Duplicating File Descriptors The redirection operator @@ -2716,7 +2727,7 @@ parameter assignments are placed in the environment for a command, not just those that precede the command name. When Bash invokes an external command, the variable @samp{$_} -is set to the full path name of the command and passed to that +is set to the full pathname of the command and passed to that command in its environment. @node Exit Status @@ -2727,7 +2738,7 @@ The exit status of an executed command is the value returned by the @var{waitpid} system call or equivalent function. Exit statuses fall between 0 and 255, though, as explained below, the shell may use values above 125 specially. Exit statuses from shell builtins and -compound commands are also limited to this range. Under certain +compound commands are also limited to this range. Under certain circumstances, the shell will use special values to indicate specific failure modes. @@ -2920,6 +2931,7 @@ These commands are implemented as specified by the @sc{posix} standard. @example : [@var{arguments}] @end example + Do nothing beyond expanding @var{arguments} and performing redirections. The return status is zero. @@ -2928,6 +2940,7 @@ The return status is zero. @example . @var{filename} [@var{arguments}] @end example + Read and execute commands from the @var{filename} argument in the current shell context. If @var{filename} does not contain a slash, the @env{PATH} variable is used to find @var{filename}. @@ -2946,6 +2959,7 @@ This builtin is equivalent to @code{source}. @example break [@var{n}] @end example + Exit from a @code{for}, @code{while}, @code{until}, or @code{select} loop. If @var{n} is supplied, the @var{n}th enclosing loop is exited. @var{n} must be greater than or equal to 1. @@ -2956,6 +2970,7 @@ The return status is zero unless @var{n} is not greater than or equal to 1. @example cd [-L|[-P [-e]]] [@var{directory}] @end example + Change the current working directory to @var{directory}. If @var{directory} is not given, the value of the @env{HOME} shell variable is used. @@ -2984,6 +2999,7 @@ non-zero otherwise. @example continue [@var{n}] @end example + Resume the next iteration of an enclosing @code{for}, @code{while}, @code{until}, or @code{select} loop. If @var{n} is supplied, the execution of the @var{n}th enclosing loop @@ -2996,6 +3012,7 @@ The return status is zero unless @var{n} is not greater than or equal to 1. @example eval [@var{arguments}] @end example + The arguments are concatenated together into a single command, which is then read and executed, and its exit status returned as the exit status of @code{eval}. @@ -3007,6 +3024,7 @@ zero. @example exec [-cl] [-a @var{name}] [@var{command} [@var{arguments}]] @end example + If @var{command} is supplied, it replaces the shell without creating a new process. If the @option{-l} option is supplied, the shell places a dash at the @@ -3016,6 +3034,11 @@ The @option{-c} option causes @var{command} to be executed with an empty environment. If @option{-a} is supplied, the shell passes @var{name} as the zeroth argument to @var{command}. +If @var{command} +cannot be executed for some reason, a non-interactive shell exits, +unless the @code{execfail} shell option +is enabled. In that case, it returns failure. +An interactive shell returns failure if the file cannot be executed. If no @var{command} is specified, redirections may be used to affect the current shell environment. If there are no redirection errors, the return status is zero; otherwise the return status is non-zero. @@ -3025,6 +3048,7 @@ return status is zero; otherwise the return status is non-zero. @example exit [@var{n}] @end example + Exit the shell, returning a status of @var{n} to the shell's parent. If @var{n} is omitted, the exit status is that of the last command executed. Any trap on @code{EXIT} is executed before the shell terminates. @@ -3034,12 +3058,13 @@ Any trap on @code{EXIT} is executed before the shell terminates. @example export [-fn] [-p] [@var{name}[=@var{value}]] @end example + Mark each @var{name} to be passed to child processes in the environment. If the @option{-f} option is supplied, the @var{name}s refer to shell functions; otherwise the names refer to shell variables. The @option{-n} option means to no longer mark each @var{name} for export. If no @var{names} are supplied, or if the @option{-p} option is given, a -list of exported names is displayed. +list of names of all exported variables is displayed. The @option{-p} option displays output in a form that may be reused as input. If a variable name is followed by =@var{value}, the value of the variable is set to @var{value}. @@ -3053,10 +3078,11 @@ with a name that is not a shell function. @example getopts @var{optstring} @var{name} [@var{args}] @end example + @code{getopts} is used by shell scripts to parse positional parameters. @var{optstring} contains the option characters to be recognized; if a character is followed by a colon, the option is expected to have an -argument, which should be separated from it by white space. +argument, which should be separated from it by whitespace. The colon (@samp{:}) and question mark (@samp{?}) may not be used as option characters. Each time it is invoked, @code{getopts} @@ -3083,7 +3109,7 @@ given in @var{args}, @code{getopts} parses those instead. @code{getopts} can report errors in two ways. If the first character of @var{optstring} is a colon, @var{silent} -error reporting is used. In normal operation diagnostic messages +error reporting is used. In normal operation, diagnostic messages are printed when invalid options or missing option arguments are encountered. If the variable @env{OPTERR} @@ -3107,6 +3133,7 @@ If @code{getopts} is silent, then a colon (@samp{:}) is placed in @example hash [-r] [-p @var{filename}] [-dt] [@var{name}] @end example + Each time @code{hash} is invoked, it remembers the full pathnames of the commands specified as @var{name} arguments, so they need not be searched for on subsequent invocations. @@ -3134,6 +3161,7 @@ option is supplied. @example pwd [-LP] @end example + Print the absolute pathname of the current working directory. If the @option{-P} option is supplied, the pathname printed will not contain symbolic links. @@ -3148,6 +3176,7 @@ is supplied. @example readonly [-aAf] [-p] [@var{name}[=@var{value}]] @dots{} @end example + Mark each @var{name} as readonly. The values of these names may not be changed by subsequent assignment. If the @option{-f} option is supplied, each @var{name} refers to a shell @@ -3173,11 +3202,14 @@ or the @option{-f} option is supplied with a name that is not a shell function. @example return [@var{n}] @end example -Cause a shell function to exit with the return value @var{n}. + +Cause a shell function to stop executing and return the value @var{n} +to its caller. If @var{n} is not supplied, the return value is the exit status of the last command executed in the function. -This may also be used to terminate execution of a script being executed -with the @code{.} (or @code{source}) builtin, returning either @var{n} or +@code{return} may also be used to terminate execution of a script +being executed with the @code{.} (@code{source}) builtin, +returning either @var{n} or the exit status of the last command executed within the script as the exit status of the script. Any command associated with the @code{RETURN} trap is executed @@ -3190,6 +3222,7 @@ and not during the execution of a script by @code{.} or @code{source}. @example shift [@var{n}] @end example + Shift the positional parameters to the left by @var{n}. The positional parameters from @var{n}+1 @dots{} @code{$#} are renamed to @code{$1} @dots{} @code{$#}-@var{n}. @@ -3202,11 +3235,16 @@ If @var{n} is not supplied, it is assumed to be 1. The return status is zero unless @var{n} is greater than @code{$#} or less than zero, non-zero otherwise. -@item test +@item test[B @itemx [ @btindex test @btindex [ -Evaluate a conditional expression @var{expr}. +@example +test @var{expr} +@end example + +Evaluate a conditional expression @var{expr} and return a status of 0 +(true) or 1 (false). Each operator and operand must be a separate argument. Expressions are composed of the primaries described below in @ref{Bash Conditional Expressions}. @@ -3289,6 +3327,7 @@ operators sort lexicographically using ASCII ordering. @example times @end example + Print out the user and system times used by the shell and its children. The return status is zero. @@ -3297,6 +3336,7 @@ The return status is zero. @example trap [-lp] [@var{arg}] [@var{sigspec} @dots{}] @end example + The commands in @var{arg} are to be read and executed when the shell receives signal @var{sigspec}. If @var{arg} is absent (and there is a single @var{sigspec}) or @@ -3351,6 +3391,7 @@ valid signal. @example umask [-p] [-S] [@var{mode}] @end example + Set the shell process's file creation mask to @var{mode}. If @var{mode} begins with a digit, it is interpreted as an octal number; if not, it is interpreted as a symbolic mode mask similar @@ -3372,7 +3413,8 @@ results in permissions of @code{755}. @example unset [-fv] [@var{name}] @end example -Each variable or function @var{name} is removed. + +Remove each variable or function @var{name}. If the @option{-v} option is given, each @var{name} refers to a shell variable and that variable is remvoved. If the @option{-f} option is given, the @var{name}s refer to shell @@ -3396,7 +3438,7 @@ Some of these commands are specified in the @sc{posix} standard. @item alias @btindex alias @example -alias [@code{-p}] [@var{name}[=@var{value}] @dots{}] +alias [-p] [@var{name}[=@var{value}] @dots{}] @end example Without arguments or with the @option{-p} option, @code{alias} prints @@ -3503,6 +3545,7 @@ error occurs. @example builtin [@var{shell-builtin} [@var{args}]] @end example + Run a shell builtin, passing it @var{args}, and return its exit status. This is useful when defining a shell function with the same name as a shell builtin, retaining the functionality of the builtin within @@ -3515,6 +3558,7 @@ builtin command. @example caller [@var{expr}] @end example + Returns the context of any active subroutine call (a shell function or a script executed with the @code{.} or @code{source} builtins). @@ -3535,6 +3579,7 @@ call stack. @example command [-pVv] @var{command} [@var{arguments} @dots{}] @end example + Runs @var{command} with @var{arguments} ignoring any shell function named @var{command}. Only shell builtin commands or commands found by searching the @@ -3558,7 +3603,7 @@ zero if @var{command} is found, and non-zero if not. @item declare @btindex declare @example -declare [-aAfFilrtux] [-p] [@var{name}[=@var{value}] @dots{}] +declare [-aAfFgilrtux] [-p] [@var{name}[=@var{value}] @dots{}] @end example Declare variables and give them attributes. If no @var{name}s @@ -3635,7 +3680,7 @@ with the exceptions that @samp{+a} may not be used to destroy an array variable and @samp{+r} will not remove the readonly attribute. When used in a function, @code{declare} makes each @var{name} local, -as with the @code{local} command, unless the @samp{-g} option is used. +as with the @code{local} command, unless the @option{-g} option is used. If a variable name is followed by =@var{value}, the value of the variable is set to @var{value}. @@ -3654,6 +3699,7 @@ or an attempt is made to display a non-existent function with @option{-f}. @example echo [-neE] [@var{arg} @dots{}] @end example + Output the @var{arg}s, separated by spaces, terminated with a newline. The return status is 0 unless a write error occurs. @@ -3709,6 +3755,7 @@ the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value @example enable [-a] [-dnps] [-f @var{filename}] [@var{name} @dots{}] @end example + Enable and disable builtin shell commands. Disabling a builtin allows a disk command which has the same name as a shell builtin to be executed without specifying a full pathname, @@ -3741,6 +3788,7 @@ or there is an error loading a new builtin from a shared object. @example help [-dms] [@var{pattern}] @end example + Display helpful information about builtin commands. If @var{pattern} is specified, @code{help} gives detailed help on all commands matching @var{pattern}, otherwise a list of @@ -3762,8 +3810,9 @@ The return status is zero unless no command matches @var{pattern}. @item let @btindex let @example -let @var{expression} [@var{expression}] +let @var{expression} [@var{expression} @dots{}] @end example + The @code{let} builtin allows arithmetic to be performed on shell variables. Each @var{expression} is evaluated according to the rules given below in @ref{Shell Arithmetic}. If the @@ -3775,6 +3824,7 @@ otherwise 0 is returned. @example local [@var{option}] @var{name}[=@var{value}] @dots{} @end example + For each argument, a local variable named @var{name} is created, and assigned @var{value}. The @var{option} can be any of the options accepted by @code{declare}. @@ -3789,20 +3839,23 @@ readonly variable. @example logout [@var{n}] @end example + Exit a login shell, returning a status of @var{n} to the shell's parent. @item mapfile @btindex mapfile @example -mapfile [-n @var{count}] [-O @var{origin}] [-s @var{count}] [-t] [-u @var{fd}] [ --C @var{callback}] [-c @var{quantum}] [@var{array}] +mapfile [-n @var{count}] [-O @var{origin}] [-s @var{count}] [-t] [-u @var{fd}] + [-C @var{callback}] [-c @var{quantum}] [@var{array}] @end example + Read lines from the standard input into the indexed array variable @var{array}, or from file descriptor @var{fd} if the @option{-u} option is supplied. The variable @code{MAPFILE} is the default @var{array}. Options, if supplied, have the following meanings: + @table @code @item -n @@ -3843,6 +3896,7 @@ is not an indexed array. @example printf [-v @var{var}] @var{format} [@var{arguments}] @end example + Write the formatted @var{arguments} to the standard output under the control of the @var{format}. The @option{-v} option causes the output to be assigned to the variable @@ -3858,16 +3912,16 @@ interprets the following extensions: @table @code @item %b -causes @code{printf} to expand backslash escape sequences in the +Causes @code{printf} to expand backslash escape sequences in the corresponding @var{argument}, -(except that @samp{\c} terminates output, backslashes in +except that @samp{\c} terminates output, backslashes in @samp{\'}, @samp{\"}, and @samp{\?} are not removed, and octal escapes -beginning with @samp{\0} may contain up to four digits). +beginning with @samp{\0} may contain up to four digits. @item %q -causes @code{printf} to output the +Causes @code{printf} to output the corresponding @var{argument} in a format that can be reused as shell input. @item %(@var{datefmt})T -causes @code{printf} to output the date-time string resulting from using +Causes @code{printf} to output the date-time string resulting from using @var{datefmt} as a format string for @code{strftime}(3). The corresponding @var{argument} is an integer representing the number of seconds since the epoch. Two special argument values may be used: -1 represents the current @@ -3889,8 +3943,10 @@ non-zero on failure. @item read @btindex read @example -read [-ers] [-a @var{aname}] [-d @var{delim}] [-i @var{text}] [-n @var{nchars}] [-N @var{nchars}] [-p @var{prompt}] [-t @var{timeout}] [-u @var{fd}] [@var{name} @dots{}] +read [-ers] [-a @var{aname}] [-d @var{delim}] [-i @var{text}] [-n @var{nchars}] + [-N @var{nchars}] [-p @var{prompt}] [-t @var{timeout}] [-u @var{fd}] [@var{name} @dots{}] @end example + One line is read from the standard input, or from the file descriptor @var{fd} supplied as an argument to the @option{-u} option, and the first word is assigned to the first @var{name}, the second word to the second @var{name}, @@ -3966,21 +4022,22 @@ the decimal point. This option is only effective if @code{read} is reading input from a terminal, pipe, or other special file; it has no effect when reading from regular files. -If @var{timeout} is 0, @code{read} returns success if input is available on -the specified file descriptor, failure otherwise. +If @var{timeout} is 0, @code{read} returns immediately, without trying to +read and data. The exit status is 0 if input is available on +the specified file descriptor, non-zero otherwise. The exit status is greater than 128 if the timeout is exceeded. @item -u @var{fd} Read input from file descriptor @var{fd}. - @end table @item readarray @btindex readarray @example -readarray [-n @var{count}] [-O @var{origin}] [-s @var{count}] [-t] [-u @var{fd}] [ --C @var{callback}] [-c @var{quantum}] [@var{array}] +readarray [-n @var{count}] [-O @var{origin}] [-s @var{count}] [-t] [-u @var{fd}] + [-C @var{callback}] [-c @var{quantum}] [@var{array}] @end example + Read lines from the standard input into the indexed array variable @var{array}, or from file descriptor @var{fd} if the @option{-u} option is supplied. @@ -3992,6 +4049,7 @@ A synonym for @code{mapfile}. @example source @var{filename} @end example + A synonym for @code{.} (@pxref{Bourne Shell Builtins}). @item type @@ -3999,6 +4057,7 @@ A synonym for @code{.} (@pxref{Bourne Shell Builtins}). @example type [-afptP] [@var{name} @dots{}] @end example + For each @var{name}, indicate how it would be interpreted if used as a command name. @@ -4018,7 +4077,7 @@ The @option{-P} option forces a path search for each @var{name}, even if @option{-t} would not return @samp{file}. If a command is hashed, @option{-p} and @option{-P} print the hashed value, -not necessarily the file that appears first in @code{$PATH}. +which is not necessarily the file that appears first in @code{$PATH}. If the @option{-a} option is used, @code{type} returns all of the places that contain an executable named @var{file}. @@ -4034,20 +4093,23 @@ if any are not found. @item typeset @btindex typeset @example -typeset [-afFrxi] [-p] [@var{name}[=@var{value}] @dots{}] +typeset [-afFgrxilrtux] [-p] [@var{name}[=@var{value}] @dots{}] @end example + The @code{typeset} command is supplied for compatibility with the Korn -shell; however, it has been deprecated in favor of the @code{declare} -builtin command. +shell. +It is a synonym for the @code{declare} builtin command. @item ulimit @btindex ulimit @example ulimit [-abcdefilmnpqrstuvxHST] [@var{limit}] @end example + @code{ulimit} provides control over the resources available to processes started by the shell, on systems that allow such control. If an option is given, it is interpreted as follows: + @table @code @item -S Change and report the soft limit associated with a resource. @@ -4113,11 +4175,11 @@ The maximum number of file locks. @item -T The maximum number of threads. - @end table -If @var{limit} is given, it is the new value of the specified resource; -the special @var{limit} values @code{hard}, @code{soft}, and +If @var{limit} is given, and the @option{-a} option is not used, +@var{limit} is the new value of the specified resource. +The special @var{limit} values @code{hard}, @code{soft}, and @code{unlimited} stand for the current hard limit, the current soft limit, and no limit, respectively. A hard limit cannot be increased by a non-root user once it is set; @@ -4127,9 +4189,9 @@ is printed, unless the @option{-H} option is supplied. When setting new limits, if neither @option{-H} nor @option{-S} is supplied, both the hard and soft limits are set. If no option is given, then @option{-f} is assumed. Values are in 1024-byte -increments, except for @option{-t}, which is in seconds, @option{-p}, -which is in units of 512-byte blocks, and @option{-n} and @option{-u}, which -are unscaled values. +increments, except for @option{-t}, which is in seconds; @option{-p}, +which is in units of 512-byte blocks; and @option{-T}, @option{-b}, +@option{-n} and @option{-u}, which are unscaled values. The return status is zero unless an invalid option or argument is supplied, or an error occurs while setting a new limit. @@ -4143,7 +4205,6 @@ unalias [-a] [@var{name} @dots{} ] Remove each @var{name} from the list of aliases. If @option{-a} is supplied, all aliases are removed. Aliases are described in @ref{Aliases}. - @end table @node Modifying Shell Behavior @@ -4336,9 +4397,9 @@ processed, shell functions are not inherited from the environment, and the @env{SHELLOPTS}, @env{BASHOPTS}, @env{CDPATH} and @env{GLOBIGNORE} variables, if they appear in the environment, are ignored. If the shell is started with the effective user (group) id not equal to the -real user (group) id, and the @code{-p} option is not supplied, these actions +real user (group) id, and the @option{-p} option is not supplied, these actions are taken and the effective user id is set to the real user id. -If the @code{-p} option is supplied at startup, the effective user id is +If the @option{-p} option is supplied at startup, the effective user id is not reset. Turning this option off causes the effective user and group ids to be set to the real user and group ids. @@ -4447,6 +4508,7 @@ This builtin allows you to change additional shell optional behavior. @example shopt [-pqsu] [-o] [@var{optname} @dots{}] @end example + Toggle the values of variables controlling optional shell behavior. With no options, or with the @option{-p} option, a list of all settable options is displayed, with an indication of whether or not each is set. @@ -4475,7 +4537,7 @@ Restricts the values of @end table If either @option{-s} or @option{-u} -is used with no @var{optname} arguments, the display is limited to +is used with no @var{optname} arguments, @code{shopt} shows only those options which are set or unset, respectively. Unless otherwise noted, the @code{shopt} options are disabled (off) @@ -4558,6 +4620,23 @@ parameter expansion as a special character. The single quotes must match quoted. This is the behavior of @sc{posix} mode through version 4.1. The default Bash behavior remains as in previous versions. +@item complete_fullquote +If set, Bash +quotes all shell metacharacters in filenames and directory names when +performing completion. +If not set, Bash +removes metacharacters such as the dollar sign from the set of +characters that will be quoted in completed filenames +when these metacharacters appear in shell variable references in words to be +completed. +This means that dollar signs in variable names that expand to directories +will not be quoted; +however, any dollar signs appearing in filenames will not be quoted, either. +This is active only when bash is using backslashes to quote completed +filenames. +This variable is set by default, which is the default Bash behavior in +versions through 4.2. + @item direxpand If set, Bash replaces directory names with the results of word expansion when performing @@ -4735,7 +4814,7 @@ This option is enabled by default. If set, prompt strings undergo parameter expansion, command substitution, arithmetic expansion, and quote removal after being expanded -as described below (@pxref{Printing a Prompt}). +as described below (@pxref{Controlling the Prompt}). This option is enabled by default. @item restricted_shell @@ -4766,7 +4845,6 @@ The return status when listing options is zero if all @var{optnames} are enabled, non-zero otherwise. When setting or unsetting options, the return status is zero unless an @var{optname} is not a valid shell option. - @end table @node Special Builtins @@ -4844,7 +4922,7 @@ the specified file or Maildir-format directory. A colon-separated list of filenames which the shell periodically checks for new mail. Each list entry can specify the message that is printed when new mail -arrives in the mail file by separating the file name from the message with +arrives in the mail file by separating the filename from the message with a @samp{?}. When used in the text of the message, @code{$_} expands to the name of the current mail file. @@ -4866,7 +4944,7 @@ or trailing colon. @item PS1 The primary prompt string. The default value is @samp{\s-\v\$ }. -@xref{Printing a Prompt}, for the complete list of escape +@xref{Controlling the Prompt}, for the complete list of escape sequences that are expanded before @env{PS1} is displayed. @item PS2 @@ -5009,7 +5087,6 @@ The release status (e.g., @var{beta1}). @item BASH_VERSINFO[5] The value of @env{MACHTYPE}. - @end table @item BASH_VERSION @@ -5127,9 +5204,9 @@ builtin command. @item FIGNORE A colon-separated list of suffixes to ignore when performing filename completion. -A file name whose suffix matches one of the entries in +A filename whose suffix matches one of the entries in @env{FIGNORE} -is excluded from the list of matched file names. A sample +is excluded from the list of matched filenames. A sample value is @samp{.o:~} @item FUNCNAME @@ -5358,10 +5435,10 @@ in the most-recently-executed foreground pipeline (which may contain only a single command). @item POSIXLY_CORRECT -If this variable is in the environment when @code{bash} starts, the shell +If this variable is in the environment when Bash starts, the shell enters @sc{posix} mode (@pxref{Bash POSIX Mode}) before reading the startup files, as if the @option{--posix} invocation option had been supplied. -If it is set while the shell is running, @code{bash} enables @sc{posix} mode, +If it is set while the shell is running, Bash enables @sc{posix} mode, as if the command @example @code{set -o posix} @@ -5380,7 +5457,7 @@ before the printing of each primary prompt (@env{$PS1}). @item PROMPT_DIRTRIM If set to a number greater than zero, the value is used as the number of trailing directory components to retain when expanding the @code{\w} and -@code{\W} prompt string escapes (@pxref{Printing a Prompt}). +@code{\W} prompt string escapes (@pxref{Controlling the Prompt}). Characters removed are replaced with an ellipsis. @item PS3 @@ -5511,7 +5588,7 @@ The numeric real user id of the current user. This variable is readonly. @node Bash Features @chapter Bash Features -This section describes features unique to Bash. +This chapter describes features unique to Bash. @menu * Invoking Bash:: Command line options that you can give @@ -5524,7 +5601,7 @@ This section describes features unique to Bash. * Aliases:: Substituting one command for another. * Arrays:: Array Variables. * The Directory Stack:: History of visited directories. -* Printing a Prompt:: Controlling the PS1 string. +* Controlling the Prompt:: Customizing the various prompt strings. * The Restricted Shell:: A more controlled mode of shell execution. * Bash POSIX Mode:: Making Bash behave more closely to what the POSIX standard specifies. @@ -5603,7 +5680,6 @@ Equivalent to @option{-v}. Print shell input lines as they're read. @item --version Show version information for this instance of Bash on the standard output and exit successfully. - @end table There are several single-character options that may be supplied at @@ -5661,7 +5737,6 @@ that may be reused as input. A @code{--} signals the end of options and disables further option processing. Any arguments after the @code{--} are treated as filenames and arguments. - @end table @cindex login shell @@ -5693,7 +5768,7 @@ in the script. If no commands are executed, the exit status is 0. This section describes how Bash executes its startup files. If any of the files exist but cannot be read, Bash reports an error. -Tildes are expanded in file names as described above under +Tildes are expanded in filenames as described above under Tilde Expansion (@pxref{Tilde Expansion}). Interactive shells are described in @ref{Interactive Shells}. @@ -5739,7 +5814,7 @@ following command were executed: @end example @noindent but the value of the @env{PATH} variable is not used to search for the -file name. +filename. As noted above, if a non-interactive shell is invoked with the @option{--login} option, Bash attempts to read and execute commands from the @@ -5795,12 +5870,12 @@ allow them to be specified. @subsubheading Invoked with unequal effective and real @sc{uid/gid}s If Bash is started with the effective user (group) id not equal to the -real user (group) id, and the @code{-p} option is not supplied, no startup +real user (group) id, and the @option{-p} option is not supplied, no startup files are read, shell functions are not inherited from the environment, the @env{SHELLOPTS}, @env{BASHOPTS}, @env{CDPATH}, and @env{GLOBIGNORE} variables, if they appear in the environment, are ignored, and the effective user id is set to the real user id. -If the @code{-p} option is supplied at invocation, the startup behavior is +If the @option{-p} option is supplied at invocation, the startup behavior is the same, but the effective user id is not reset. @node Interactive Shells @@ -6096,7 +6171,6 @@ is equal to, not equal to, less than, less than or equal to, greater than, or greater than or equal to @var{arg2}, respectively. @var{Arg1} and @var{arg2} may be positive or negative integers. - @end table @node Shell Arithmetic @@ -6227,8 +6301,9 @@ aliases, but a word that is identical to an alias being expanded is not expanded a second time. This means that one may alias @code{ls} to @code{"ls -F"}, for instance, and Bash does not try to recursively expand the -replacement text. If the last character of the alias value is a -space or tab character, then the next command word following the +replacement text. +If the last character of the alias value is a +@var{blank}, then the next command word following the alias is also checked for alias expansion. Aliases are created and listed with the @code{alias} @@ -6281,7 +6356,7 @@ associative arrays use arbitrary strings. An indexed array is created automatically if any variable is assigned to using the syntax @example -name[@var{subscript}]=@var{value} +@var{name}[@var{subscript}]=@var{value} @end example @noindent @@ -6299,6 +6374,7 @@ declare -a @var{name}[@var{subscript}] @noindent is also accepted; the @var{subscript} is ignored. +@noindent Associative arrays are created using @example declare -A @var{name}. @@ -6311,12 +6387,12 @@ an array. Arrays are assigned to using compound assignments of the form @example -name=(value@var{1} @dots{} value@var{n}) +@var{name}=(@var{value1} @var{value2} @dots{} ) @end example @noindent where each @var{value} is of the form @code{[@var{subscript}]=}@var{string}. -Indexed array assignments do not require the bracket and subscript. +Indexed array assignments do not require anything but @var{string}. When assigning to indexed arrays, if the optional subscript is supplied, that index is assigned to; otherwise the index of the element assigned is the last index assigned @@ -6326,29 +6402,29 @@ When assigning to an associative array, the subscript is required. This syntax is also accepted by the @code{declare} builtin. Individual array elements may be assigned to using the -@code{name[}@var{subscript}@code{]=}@var{value} syntax introduced above. +@code{@var{name}[@var{subscript}]=@var{value}} syntax introduced above. Any element of an array may be referenced using -@code{$@{name[}@var{subscript}@code{]@}}. +@code{$@{@var{name}[@var{subscript}]@}}. The braces are required to avoid conflicts with the shell's filename expansion operators. If the @var{subscript} is @samp{@@} or @samp{*}, the word expands to all members of the array @var{name}. These subscripts differ only when the word appears within double quotes. If the word is double-quoted, -@code{$@{name[*]@}} expands to a single word with +@code{$@{@var{name}[*]@}} expands to a single word with the value of each array member separated by the first character of the -@env{IFS} variable, and @code{$@{name[@@]@}} expands each element of +@env{IFS} variable, and @code{$@{@var{name}[@@]@}} expands each element of @var{name} to a separate word. When there are no array members, -@code{$@{name[@@]@}} expands to nothing. +@code{$@{@var{name}[@@]@}} expands to nothing. If the double-quoted expansion occurs within a word, the expansion of the first parameter is joined with the beginning part of the original word, and the expansion of the last parameter is joined with the last part of the original word. This is analogous to the expansion of the special parameters @samp{@@} and @samp{*}. -@code{$@{#name[}@var{subscript}@code{]@}} expands to the length of -@code{$@{name[}@var{subscript}@code{]@}}. +@code{$@{#@var{name}[@var{subscript}]@}} expands to the length of +@code{$@{@var{name}[@var{subscript}]@}}. If @var{subscript} is @samp{@@} or @samp{*}, the expansion is the number of elements in the array. Referencing an array variable without a subscript is equivalent to @@ -6363,12 +6439,12 @@ An array variable is considered set if a subscript has been assigned a value. The null string is a valid value. The @code{unset} builtin is used to destroy arrays. -@code{unset} @var{name}[@var{subscript}] +@code{unset @var{name}[@var{subscript}]} destroys the array element at index @var{subscript}. Care must be taken to avoid unwanted side effects caused by filename expansion. -@code{unset} @var{name}, where @var{name} is an array, removes the -entire array. A subscript of @samp{*} or @samp{@@} also removes the +@code{unset @var{name}}, where @var{name} is an array, removes the +entire array. A subscript of @samp{*} or @samp{@@} also removes the entire array. The @code{declare}, @code{local}, and @code{readonly} @@ -6409,37 +6485,39 @@ as the value of the @env{DIRSTACK} shell variable. @item dirs @btindex dirs @example -dirs [+@var{N} | -@var{N}] [-clpv] +dirs [-clpv] [+@var{N} | -@var{N}] @end example + Display the list of currently remembered directories. Directories are added to the list with the @code{pushd} command; the @code{popd} command removes directories from the list. + @table @code -@item +@var{N} -Displays the @var{N}th directory (counting from the left of the -list printed by @code{dirs} when invoked without options), starting -with zero. -@item -@var{N} -Displays the @var{N}th directory (counting from the right of the -list printed by @code{dirs} when invoked without options), starting -with zero. @item -c Clears the directory stack by deleting all of the elements. @item -l -Produces a longer listing; the default listing format uses a -tilde to denote the home directory. +Produces a listing using full pathnames; +the default listing format uses a tilde to denote the home directory. @item -p Causes @code{dirs} to print the directory stack with one entry per line. @item -v Causes @code{dirs} to print the directory stack with one entry per line, prefixing each entry with its index in the stack. +@item +@var{N} +Displays the @var{N}th directory (counting from the left of the +list printed by @code{dirs} when invoked without options), starting +with zero. +@item -@var{N} +Displays the @var{N}th directory (counting from the right of the +list printed by @code{dirs} when invoked without options), starting +with zero. @end table @item popd @btindex popd @example -popd [+@var{N} | -@var{N}] [-n] +popd [-n] [+@var{N} | -@var{N}] @end example Remove the top entry from the directory stack, and @code{cd} @@ -6448,23 +6526,24 @@ When no arguments are given, @code{popd} removes the top directory from the stack and performs a @code{cd} to the new top directory. The elements are numbered from 0 starting at the first directory listed with -@code{dirs}; i.e., @code{popd} is equivalent to @code{popd +0}. +@code{dirs}; that is, @code{popd} is equivalent to @code{popd +0}. + @table @code +@item -n +Suppresses the normal change of directory when removing directories +from the stack, so that only the stack is manipulated. @item +@var{N} Removes the @var{N}th directory (counting from the left of the list printed by @code{dirs}), starting with zero. @item -@var{N} Removes the @var{N}th directory (counting from the right of the list printed by @code{dirs}), starting with zero. -@item -n -Suppresses the normal change of directory when removing directories -from the stack, so that only the stack is manipulated. @end table @btindex pushd @item pushd @example -pushd [-n] [@var{+N} | @var{-N} | @var{dir} ] +pushd [-n] [@var{+N} | @var{-N} | @var{dir}] @end example Save the current directory on the top of the directory stack @@ -6484,14 +6563,13 @@ Brings the @var{N}th directory (counting from the right of the list printed by @code{dirs}, starting with zero) to the top of the list by rotating the stack. @item @var{dir} -Makes the current working directory be the top of the stack, and then -executes the equivalent of `@code{cd} @var{dir}'. -@code{cd}s to @var{dir}. +Makes the current working directory be the top of the stack, making +it the new current directory as if it had been supplied as an argument +to the @code{cd} builtin. @end table - @end table -@node Printing a Prompt +@node Controlling the Prompt @section Controlling the Prompt @cindex prompting @@ -6501,7 +6579,7 @@ has a non-null value, then the value is executed just as if it had been typed on the command line. In addition, the following table describes the special characters which -can appear in the prompt variables: +can appear in the prompt variables @env{PS1} to @env{PS4}: @table @code @item \a @@ -6728,6 +6806,10 @@ contain characters other than letters, digits, and underscores, and may not start with a digit. Declaring a function with an invalid name causes a fatal syntax error in non-interactive shells. +@item +Function names may not be the same as one of the @sc{posix} special +builtins. + @item @sc{posix} special builtins are found before shell functions during command lookup. @@ -6988,7 +7070,7 @@ previous job with a @samp{-}. A job may also be referred to using a prefix of the name used to start it, or using a substring that appears in its command line. For example, @samp{%ce} refers -to a stopped @code{ce} job. Using @samp{%?ce}, on the +to a stopped @code{ce} job. Using @samp{%?ce}, on the other hand, refers to any job containing the string @samp{ce} in its command line. If the prefix or substring matches more than one job, Bash reports an error. @@ -7025,6 +7107,7 @@ Bash does not print another warning, and any stopped jobs are terminated. @example bg [@var{jobspec} @dots{}] @end example + Resume each suspended job @var{jobspec} in the background, as if it had been started with @samp{&}. If @var{jobspec} is not supplied, the current job is used. @@ -7038,6 +7121,7 @@ that was started without job control. @example fg [@var{jobspec}] @end example + Resume the job @var{jobspec} in the foreground and make it the current job. If @var{jobspec} is not supplied, the current job is used. The return status is that of the command placed into the foreground, @@ -7067,10 +7151,10 @@ the user was last notified of their status. List only the process @sc{id} of the job's process group leader. @item -r -Restrict output to running jobs. +Display only running jobs. @item -s -Restrict output to stopped jobs. +Display only stopped jobs. @end table If @var{jobspec} is given, @@ -7089,6 +7173,7 @@ passing it @var{argument}s, returning its exit status. kill [-s @var{sigspec}] [-n @var{signum}] [-@var{sigspec}] @var{jobspec} or @var{pid} kill -l [@var{exit_status}] @end example + Send a signal specified by @var{sigspec} or @var{signum} to the process named by job specification @var{jobspec} or process @sc{id} @var{pid}. @var{sigspec} is either a case-insensitive signal name such as @@ -7107,8 +7192,9 @@ or non-zero if an error occurs or an invalid option is encountered. @item wait @btindex wait @example -wait [@var{jobspec} or @var{pid} ...] +wait [@var{jobspec} or @var{pid} @dots{}] @end example + Wait until the child process specified by each process @sc{id} @var{pid} or job specification @var{jobspec} exits and return the exit status of the last command waited for. @@ -7123,7 +7209,8 @@ of the shell, the return status is 127. @example disown [-ar] [-h] [@var{jobspec} @dots{}] @end example -Without options, each @var{jobspec} is removed from the table of + +Without options, remove each @var{jobspec} from the table of active jobs. If the @option{-h} option is given, the job is not removed from the table, but is marked so that @code{SIGHUP} is not sent to the job if the shell @@ -7139,11 +7226,11 @@ argument restricts operation to running jobs. @example suspend [-f] @end example + Suspend the execution of this shell until it receives a @code{SIGCONT} signal. A login shell cannot be suspended; the @option{-f} option can be used to override this and force the suspension. - @end table When job control is not active, the @code{kill} and @code{wait} @@ -7626,7 +7713,7 @@ If Readline is not enabled, this option has no effect. @item --enable-prompt-string-decoding Turn on the interpretation of a number of backslash-escaped characters in the @env{$PS1}, @env{$PS2}, @env{$PS3}, and @env{$PS4} prompt -strings. See @ref{Printing a Prompt}, for a complete list of prompt +strings. See @ref{Controlling the Prompt}, for a complete list of prompt string escape sequences. @item --enable-readline @@ -7666,7 +7753,6 @@ which makes the Bash @code{echo} behave more like the version specified in the Single Unix Specification, version 3. @xref{Bash Builtins}, for a description of the escape sequences that @code{echo} recognizes. - @end table The file @file{config-top.h} contains C Preprocessor @@ -8022,7 +8108,7 @@ Bash has much more optional behavior controllable with the @code{set} builtin (@pxref{The Set Builtin}). @item -The @samp{-x} (@code{xtrace}) option displays commands other than +The @samp{-x} (@option{xtrace}) option displays commands other than simple commands when performing an execution trace (@pxref{The Set Builtin}). @@ -8085,7 +8171,7 @@ Bash also makes the directory stack visible as the value of the @item Bash interprets special backslash-escaped characters in the prompt -strings when interactive (@pxref{Printing a Prompt}). +strings when interactive (@pxref{Controlling the Prompt}). @item The Bash restricted mode is more useful (@pxref{The Restricted Shell}); diff --git a/doc/version.texi b/doc/version.texi index 15784c9a9..40b6027a7 100644 --- a/doc/version.texi +++ b/doc/version.texi @@ -2,9 +2,9 @@ Copyright (C) 1988-2011 Free Software Foundation, Inc. @end ignore -@set LASTCHANGE Fri Sep 16 08:44:02 EDT 2011 +@set LASTCHANGE Sun Sep 25 22:01:31 EDT 2011 @set EDITION 4.2 @set VERSION 4.2 -@set UPDATED 16 September 2011 +@set UPDATED 25 September 2011 @set UPDATED-MONTH September 2011 diff --git a/doc/version.texi~ b/doc/version.texi~ index 3cdb3b5ef..872254658 100644 --- a/doc/version.texi~ +++ b/doc/version.texi~ @@ -2,9 +2,9 @@ Copyright (C) 1988-2011 Free Software Foundation, Inc. @end ignore -@set LASTCHANGE Sun Jul 24 16:17:58 EDT 2011 +@set LASTCHANGE Mon Sep 19 21:46:24 EDT 2011 @set EDITION 4.2 @set VERSION 4.2 -@set UPDATED 24 July 2011 -@set UPDATED-MONTH July 2011 +@set UPDATED 19 September 2011 +@set UPDATED-MONTH September 2011 diff --git a/execute_cmd.c b/execute_cmd.c index c67c363ff..149e30439 100644 --- a/execute_cmd.c +++ b/execute_cmd.c @@ -5184,6 +5184,14 @@ execute_intern_function (name, function) return (EXECUTION_FAILURE); } + /* Posix interpretation 383 */ + if (posixly_correct && find_special_builtin (name->word)) + { + internal_error (_("`%s': is a special builtin"), name->word); + last_command_exit_value = EX_BADUSAGE; + jump_to_top_level (ERREXIT); + } + var = find_function (name->word); if (var && (readonly_p (var) || noassign_p (var))) { diff --git a/expr.c b/expr.c index b1dddede7..aad2a382f 100644 --- a/expr.c +++ b/expr.c @@ -829,6 +829,23 @@ exp2 () return (val1); } +static intmax_t +ipow (base, exp) + intmax_t base, exp; +{ + intmax_t result; + + result = 1; + while (exp) + { + if (exp & 1) + result *= base; + exp >>= 1; + base *= base; + } + return result; +} + static intmax_t exppower () { @@ -843,9 +860,7 @@ exppower () return (1); if (val2 < 0) evalerror (_("exponent less than 0")); - for (c = 1; val2--; c *= val1) - ; - val1 = c; + val1 = ipow (val1, val2); } return (val1); } diff --git a/lib/intl/localealias.c b/lib/intl/localealias.c index d99a48d9e..0d5ded71b 100644 --- a/lib/intl/localealias.c +++ b/lib/intl/localealias.c @@ -305,7 +305,10 @@ read_alias_file (fname, fname_len) if (nmap >= maxmap) if (__builtin_expect (extend_alias_table (), 0)) - return added; + { + fclose (fp); + return added; + } alias_len = strlen (alias) + 1; value_len = strlen (value) + 1; diff --git a/lib/readline/complete.c b/lib/readline/complete.c index 6acdca48e..f5910863f 100644 --- a/lib/readline/complete.c +++ b/lib/readline/complete.c @@ -2241,8 +2241,9 @@ rl_filename_completion_function (text, state) } directory = opendir (dirname); - /* Now dequote a non-null filename. */ - if (filename && *filename && rl_completion_found_quote && rl_filename_dequoting_function) + /* Now dequote a non-null filename. FILENAME will not be NULL, but may + be empty. */ + if (*filename && rl_completion_found_quote && rl_filename_dequoting_function) { /* delete single and double quotes */ temp = (*rl_filename_dequoting_function) (filename, rl_completion_quote_character); diff --git a/lib/readline/doc/hsuser.texi b/lib/readline/doc/hsuser.texi index 75df3ee48..b999fd988 100644 --- a/lib/readline/doc/hsuser.texi +++ b/lib/readline/doc/hsuser.texi @@ -141,8 +141,10 @@ history list and history file. @code{fc -s [@var{pat}=@var{rep}] [@var{command}]} @end example -Fix Command. In the first form, a range of commands from @var{first} to -@var{last} is selected from the history list. Both @var{first} and +The first form selects a range of commands from @var{first} to +@var{last} from the history list and displays or edits and re-executes +them. +Both @var{first} and @var{last} may be specified as a string (to locate the most recent command beginning with that string) or as a number (an index into the history list, where a negative number is used as an offset from the @@ -161,6 +163,7 @@ When editing is complete, the edited commands are echoed and executed. In the second form, @var{command} is re-executed after each instance of @var{pat} in the selected command is replaced by @var{rep}. +@var{command} is intepreted the same as @var{first} above. A useful alias to use with the @code{fc} command is @code{r='fc -s'}, so that typing @samp{r cc} runs the last command beginning with @code{cc} @@ -208,11 +211,11 @@ to the current history list. These are lines appended to the history file since the beginning of the current Bash session. @item -r -Read the current history file and append its contents to +Read the history file and append its contents to the history list. @item -w -Write out the current history to the history file. +Write out the current history list to the history file. @item -p Perform history substitution on the @var{arg}s and display the result diff --git a/po/sl.po b/po/sl.po index 1b848d42c..07c8320e7 100644 --- a/po/sl.po +++ b/po/sl.po @@ -3,13 +3,13 @@ # This file is distributed under the same license as the bash package. # Primož PETERLIN , 2011. # -# $Id: bash-4.2.sl.po,v 1.9 2011/08/06 20:04:00 peterlin Exp $ +# $Id: bash-4.2.sl.po,v 1.10 2011/09/20 19:33:18 peterlin Exp $ msgid "" msgstr "" "Project-Id-Version: bash 4.2\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2011-01-28 22:09-0500\n" -"PO-Revision-Date: 2011-08-06 22:03+0200\n" +"PO-Revision-Date: 2011-09-20 21:31+0200\n" "Last-Translator: Primož PETERLIN \n" "Language-Team: Slovenian \n" "Language: sl\n" @@ -440,8 +440,10 @@ msgstr "zadetki\tukaz\n" #, c-format msgid "Shell commands matching keyword `" msgid_plural "Shell commands matching keywords `" -msgstr[0] "" -msgstr[1] "" +msgstr[0] "Ukazev lupine, ujemajočih se s ključno besedo »" +msgstr[1] "Ukaz lupine, ujemajoč se s ključno besedo »" +msgstr[2] "Ukaza lupine, ujemajoča se s ključno besedo »" +msgstr[3] "Ukazi lupine, ujemajoči se s ključno besedo »" #: builtins/help.def:168 #, c-format @@ -478,21 +480,21 @@ msgstr "uporabite lahko le eno od izbir -anrw" #: builtins/history.def:186 msgid "history position" -msgstr "" +msgstr "položaj v zgodovini" #: builtins/history.def:365 #, c-format msgid "%s: history expansion failed" -msgstr "" +msgstr "%s: neuspešna razrešitev zgodovine" #: builtins/inlib.def:71 #, c-format msgid "%s: inlib failed" -msgstr "" +msgstr "%s: neuspel klic inlib" #: builtins/jobs.def:109 msgid "no other options allowed with `-x'" -msgstr "" +msgstr "nobena druga izbira ni dovoljena skupaj z »-x«" #: builtins/kill.def:198 #, c-format @@ -814,7 +816,7 @@ msgstr "" #: builtins/ulimit.def:402 #, c-format msgid "`%c': bad command" -msgstr "" +msgstr "»%c«: slab ukaz" #: builtins/ulimit.def:431 #, c-format @@ -860,19 +862,19 @@ msgstr "Prekinjanje.." #: error.c:406 msgid "unknown command error" -msgstr "" +msgstr "neznana ukazna napaka" #: error.c:407 msgid "bad command type" -msgstr "" +msgstr "slaba zvrst ukaza" #: error.c:408 msgid "bad connector" -msgstr "" +msgstr "slab konektor" #: error.c:409 msgid "bad jump" -msgstr "" +msgstr "slab skok" #: error.c:447 #, c-format @@ -882,7 +884,7 @@ msgstr "" #: eval.c:181 #, c-format msgid "\atimed out waiting for input: auto-logout\n" -msgstr "" +msgstr "\ačasovna prekoračitev pri čakanju na vhod: samodejna odjava\n" #: execute_cmd.c:504 #, c-format @@ -892,11 +894,11 @@ msgstr "standardnega vhoda ni mogoče preusmeriti iz /dev/null: %s" #: execute_cmd.c:1168 #, c-format msgid "TIMEFORMAT: `%c': invalid format character" -msgstr "" +msgstr "TIMEFORMAT: »%c«: neveljavni formatni znak" #: execute_cmd.c:2121 msgid "pipe error" -msgstr "" +msgstr "napaka cevovoda" #: execute_cmd.c:4640 #, c-format @@ -916,7 +918,7 @@ msgstr "%s: %s" #: execute_cmd.c:4995 #, c-format msgid "%s: %s: bad interpreter" -msgstr "" +msgstr "%s: %s: slab tolmač" #: execute_cmd.c:5144 #, c-format @@ -1010,17 +1012,17 @@ msgstr "" #: jobs.c:468 msgid "start_pipeline: pgrp pipe" -msgstr "" +msgstr "start_pipeline: cevovod pgrp" #: jobs.c:889 #, c-format msgid "forked pid %d appears in running job %d" -msgstr "" +msgstr "vejeni PID %d se pojavlja v tekočem poslu %d" #: jobs.c:1007 #, c-format msgid "deleting stopped job %d with process group %ld" -msgstr "" +msgstr "brisanje ustavljenega posla %d s skupino procesa %ld" #: jobs.c:1112 #, c-format @@ -1091,17 +1093,17 @@ msgstr "" #: jobs.c:2133 nojobs.c:585 #, c-format msgid "wait: pid %ld is not a child of this shell" -msgstr "" +msgstr "wait: PID %ld ni naslednik te lupine" #: jobs.c:2360 #, c-format msgid "wait_for: No record of process %ld" -msgstr "" +msgstr "wait_for: Ni zapisa za proces %ld" #: jobs.c:2637 #, c-format msgid "wait_for_job: job %d is stopped" -msgstr "" +msgstr "wait_for_job: posel %d je ustavljen" #: jobs.c:2859 #, c-format @@ -1125,7 +1127,7 @@ msgstr "%s: vrstica %d: " #: jobs.c:3552 nojobs.c:814 #, c-format msgid " (core dumped)" -msgstr "" +msgstr " (izmet pomnilnika)" #: jobs.c:3564 jobs.c:3577 #, c-format @@ -1151,7 +1153,7 @@ msgstr "" #: jobs.c:3712 msgid "no job control in this shell" -msgstr "" +msgstr "ta lupina nima nadzora poslov" #: lib/malloc/malloc.c:296 #, c-format @@ -1303,76 +1305,76 @@ msgstr "" #: parse.y:3173 parse.y:3444 #, c-format msgid "unexpected EOF while looking for matching `%c'" -msgstr "" +msgstr "nepričakovani EOF pri iskanju ujemajočega »%c«" #: parse.y:4025 msgid "unexpected EOF while looking for `]]'" -msgstr "" +msgstr "nepričakovani EOF pri iskanju »]]«" #: parse.y:4030 #, c-format msgid "syntax error in conditional expression: unexpected token `%s'" -msgstr "" +msgstr "napaka v skladnji pogojnega izraza: nepričakovani žeton »%s«" #: parse.y:4034 msgid "syntax error in conditional expression" -msgstr "" +msgstr "napaka v skladnji pogojnega izraza" #: parse.y:4112 #, c-format msgid "unexpected token `%s', expected `)'" -msgstr "" +msgstr "nepričakovani žeton »%s«, pričakovan »)«" #: parse.y:4116 msgid "expected `)'" -msgstr "" +msgstr "pričakovan »)«" #: parse.y:4144 #, c-format msgid "unexpected argument `%s' to conditional unary operator" -msgstr "" +msgstr "nepričakovani argument »%s« pogojnega unarnega operatorja" #: parse.y:4148 msgid "unexpected argument to conditional unary operator" -msgstr "" +msgstr "nepričakovani argument pogojnega unarnega operatorja" #: parse.y:4194 #, c-format msgid "unexpected token `%s', conditional binary operator expected" -msgstr "" +msgstr "nepričakovani žeton »%s«, pričakovan pogojni binarni operator" #: parse.y:4198 msgid "conditional binary operator expected" -msgstr "" +msgstr "pričakovan pogojni binarni operator" #: parse.y:4220 #, c-format msgid "unexpected argument `%s' to conditional binary operator" -msgstr "" +msgstr "nepričakovani argument »%s« pogojnega binarnega operatorja" #: parse.y:4224 msgid "unexpected argument to conditional binary operator" -msgstr "" +msgstr "nepričakovani argument pogojnega binarnega operatorja" #: parse.y:4235 #, c-format msgid "unexpected token `%c' in conditional command" -msgstr "" +msgstr "nepričakovani žeton »%c« v pogojnem ukazu" #: parse.y:4238 #, c-format msgid "unexpected token `%s' in conditional command" -msgstr "" +msgstr "nepričakovani žeton »%s« v pogojnem ukazu" #: parse.y:4242 #, c-format msgid "unexpected token %d in conditional command" -msgstr "" +msgstr "nepričakovani žeton %d v pogojnem ukazu" #: parse.y:5566 #, c-format msgid "syntax error near unexpected token `%s'" -msgstr "" +msgstr "napaka v skladnji blizu nepričakovanega žetona »%s«" #: parse.y:5584 #, c-format @@ -1432,32 +1434,32 @@ msgstr "" #: redir.c:122 msgid "file descriptor out of range" -msgstr "" +msgstr "deskriptor datoteke izven obsega" #: redir.c:178 #, c-format msgid "%s: ambiguous redirect" -msgstr "" +msgstr "%s: preusmeritev ni enopomenska" #: redir.c:182 #, c-format msgid "%s: cannot overwrite existing file" -msgstr "" +msgstr "%s: prek obstoječe datoteke ni mogoče pisati" #: redir.c:187 #, c-format msgid "%s: restricted: cannot redirect output" -msgstr "" +msgstr "%s: omejitev: izhoda ni mogoče preusmeriti" #: redir.c:192 #, c-format msgid "cannot create temp file for here-document: %s" -msgstr "" +msgstr "ni mogoče ustvariti začasne datoteke za dokument: %s" #: redir.c:196 #, c-format msgid "%s: cannot assign fd to variable" -msgstr "" +msgstr "%s: fd ni mogoče pripisati spremenljivki" #: redir.c:548 msgid "/dev/(tcp|udp)/host/port not supported without networking" @@ -1465,7 +1467,7 @@ msgstr "" #: redir.c:818 redir.c:930 redir.c:993 redir.c:1136 msgid "redirection error: cannot duplicate fd" -msgstr "" +msgstr "napaka pri preusmeritvi: fd ni mogoče podvojiti" #: shell.c:333 msgid "could not find /tmp, please create!" diff --git a/tests/shopt.right b/tests/shopt.right index 08deb51e2..440a6d2da 100644 --- a/tests/shopt.right +++ b/tests/shopt.right @@ -12,6 +12,7 @@ shopt -u compat31 shopt -u compat32 shopt -u compat40 shopt -u compat41 +shopt -s complete_fullquote shopt -u direxpand shopt -u dirspell shopt -u dotglob @@ -52,6 +53,7 @@ shopt -s sourcepath -- shopt -s cdspell shopt -s cmdhist +shopt -s complete_fullquote shopt -s expand_aliases shopt -s extquote shopt -s force_fignore