Penguin
Blame: bash(1)Part3
EditPageHistoryDiffInfoLikePages
Annotated edit history of bash(1)Part3 version 1, including all changes. View license author blame.
Rev Author # Line
1 JohnMcPherson 1 !!BASH MAN PAGE (Part 3)
2
3 __Navigation__%%%
4 This man page has been split into 7 pages:%%%
5 bash(1)
6 * NAME
7 * SYNOPSIS
8 * COPYRIGHT
9 * DESCRIPTION
10 * OPTIONS
11 * ARGUMENTS
12 * INVOCATION
13
14 [bash(1)Part2]
15 * DEFINITIONS
16 * RESERVED WORDS
17 * SHELL GRAMMAR
18 * COMMENTS
19 * QUOTING
20
21 __Part 3__
22 * __PARAMETERS__
23
24 [bash(1)Part4]
25 * EXPANSION
26
27 [bash(1)Part5]
28 * REDIRECTION
29 * ALIASES
30 * FUNCTIONS
31 * ARITHMETIC EVALUATION
32 * CONDITIONAL EXPRESSIONS
33 * SIMPLE COMMAND EXPANSION
34 * COMMAND EXECUTION
35 * COMMAND EXECUTION ENVIRONMENT
36 * ENVIRONMENT
37 * EXIT STATUS
38 * SIGNALS
39 * JOB CONTROL
40 * PROMPTING
41
42 [bash(1)Part6]
43 * READLINE
44 * HISTORY
45 * HISTORY EXPANSION
46
47
48 [bash(1)Part7]
49 * SHELL BUILTIN COMMANDS
50 * RESTRICTED SHELL
51 * SEE ALSO
52 * FILES
53 * AUTHORS
54 * BUG REPORTS
55 * BUGS
56
57 ----
58 !!PARAMETERS
59 A ''parameter'' is an entity that stores values. It can be a ''name'' , a number, or one of the special characters listed below under __Special Parameters__ . For the shell's purposes, a ''variable'' is a parameter denoted by a ''name'' .
60
61 A parameter is set if it has been assigned a value. The null string is a valid value. Once a variable is set, it may be unset only by using the __unset__ builtin command (see __SHELL BUILTIN COMMANDS__ below).
62
63 A ''variable'' may be assigned to by a statement of the form
64
65 ''name''=[[''value'']
66
67
68 If ''value'' is not given, the variable is assigned the null string. All ''values'' undergo tilde expansion, parameter and variable expansion, command substitution, arithmetic expansion, and quote removal (see __EXPANSION__ below). If the variable has its __integer__ attribute set (see __declare__ below in __SHELL BUILTIN COMMANDS__ ) then ''value'' is subject to arithmetic expansion even if the $((...)) expansion is not used (see __Arithmetic Expansion__ below). Word splitting is not performed, with the exception of __"$@"__ as explained below under __Special Parameters__ . Pathname expansion is not performed.
69
70 !Positional Parameters
71
72
73 A ''positional parameter'' is a parameter denoted by one or more digits, other than the single digit 0. Positional parameters are assigned from the shell's arguments when it is invoked, and may be reassigned using the __set__ builtin command. Positional parameters may not be assigned to with assignment statements. The positional parameters are temporarily replaced when a shell function is executed (see __FUNCTIONS__ below).
74
75 When a positional parameter consisting of more than a single digit is expanded, it must be enclosed in braces (see __EXPANSION__ below).
76
77 !Special Parameters
78
79
80 The shell treats several parameters specially. These parameters may only be referenced; assignment to them is not allowed.
81
82
83 ;__*__ : Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, it expands to a single word with the value of each parameter separated by the first character of the __IFS__ special variable. That is, "__$*__" is equivalent to "__$1__''c''__$2__''c''__...__", where ''c'' is the first character of the value of the __IFS__ variable. If __IFS__ is unset, the parameters are separated by spaces. If __IFS__ is null, the parameters are joined without intervening separators.
84 ;__@__ : Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, each parameter expands to a separate word. That is, "__$@__" is equivalent to "__$1__" "__$2__" ... When there are no positional parameters, "__$@__" and __$@__ expand to nothing (i.e., they are removed).
85 ;__#__ : Expands to the number of positional parameters in decimal.
86 ;__?__ : Expands to the status of the most recently executed foreground pipeline.
87 ;__-__ : Expands to the current option flags as specified upon invocation, by the __set__ builtin command, or those set by the shell itself (such as the __-i__ option).
88 ;__$__ : Expands to the process ID of the shell. In a () subshell, it expands to the process ID of the current shell, not the subshell.
89 ;__!__ : Expands to the process ID of the most recently executed background (asynchronous) command.
90 ;__0__ : Expands to the name of the shell or shell script. This is set at shell initialization. If __bash__ is invoked with a file of commands, __$0__ is set to the name of that file. If __bash__ is started with the __-c__ option, then __$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 __bash__ , as given by argument zero.
91 ;_____ : At shell startup, set to the absolute file name of the shell or shell script being executed as passed in the argument list. Subsequently, expands to the last argument to the previous command, after expansion. Also set to the full file name of each command executed and placed in the environment exported to that command. When checking mail, this parameter holds the name of the mail file currently being checked.
92
93
94 !Shell Variables
95
96
97 The following variables are set by the shell:
98
99
100
101
102 ;__PPID__ : The process ID of the shell's parent. This variable is readonly.
103 ;__PWD__ : The current working directory as set by the __cd__ command.
104 ;__OLDPWD__ : The previous working directory as set by the __cd__ command.
105 ;__REPLY__ : Set to the line of input read by the __read__ builtin command when no arguments are supplied.
106 ;__UID__ : Expands to the user ID of the current user, initialized at shell startup. This variable is readonly.
107 ;__EUID__ : Expands to the effective user ID of the current user, initialized at shell startup. This variable is readonly.
108 ;__GROUPS__ : An array variable containing the list of groups of which the current user is a member. Assignments to __GROUPS__ have no effect and return an error status. If __GROUPS__ is unset, it loses its special properties, even if it is subsequently reset.
109 ;__BASH__ : Expands to the full file name used to invoke this instance of __bash__ .
110 ;__BASH_VERSION__ : Expands to a string describing the version of this instance of __bash__ .
111 ;__BASH_VERSINFO__ : A readonly array variable whose members hold version information for this instance of __bash__ . The values assigned to the array members are as follows:
112
113
114
115
116 ;__BASH_VERSINFO[[0]__ : The major version number (the ''release'').
117 ;__BASH_VERSINFO[[1]__ : The minor version number (the ''version'').
118 ;__BASH_VERSINFO[[2]__ : The patch level.
119 ;__BASH_VERSINFO[[3]__ : The build version.
120 ;__BASH_VERSINFO[[4]__ : The release status (e.g., ''beta1'').
121 ;__BASH_VERSINFO[[5]__ : The value of __MACHTYPE__.
122
123
124 ;__SHLVL__ : Incremented by one each time an instance of __bash__ is started.
125 ;__RANDOM__ : Each time this parameter is referenced, a random integer between 0 and 32767 is generated. The sequence of random numbers may be initialized by assigning a value to __RANDOM__ . If __RANDOM__ is unset, it loses its special properties, even if it is subsequently reset.
126 ;__SECONDS__ : Each time this parameter is referenced, the number of seconds since shell invocation is returned. If a value is assigned to __SECONDS__ , the value returned upon subsequent references is the number of seconds since the assignment plus the value assigned. If __SECONDS__ is unset, it loses its special properties, even if it is subsequently reset.
127 ;__LINENO__ : Each time this parameter is referenced, the shell substitutes a decimal number representing the current sequential line number (starting with 1) within a script or function. When not in a script or function, the value substituted is not guaranteed to be meaningful. If __LINENO__ is unset, it loses its special properties, even if it is subsequently reset.
128 ;__HISTCMD__ : The history number, or index in the history list, of the current command. If __HISTCMD__ is unset, it loses its special properties, even if it is subsequently reset.
129 ;__FUNCNAME__ : The name of any currently-executing shell function. This variable exists only when a shell function is executing. Assignments to __FUNCNAME__ have no effect and return an error status. If __FUNCNAME__ is unset, it loses its special properties, even if it is subsequently reset.
130 ;__DIRSTACK__ : An array variable (see __Arrays__ below) containing the current contents of the directory stack. Directories appear in the stack in the order they are displayed by the __dirs__ builtin. Assigning to members of this array variable may be used to modify directories already in the stack, but the __pushd__ and __popd__ builtins must be used to add and remove directories. Assignment to this variable will not change the current directory. If __DIRSTACK__ is unset, it loses its special properties, even if it is subsequently reset.
131 ;__PIPESTATUS__ : An array variable (see __Arrays__ below) containing a list of exit status values from the processes in the most-recently-executed foreground pipeline (which may contain only a single command).
132 ;__OPTARG__ : The value of the last option argument processed by the __getopts__ builtin command (see __SHELL BUILTIN COMMANDS__ below).
133 ;__OPTIND__ : The index of the next argument to be processed by the __getopts__ builtin command (see __SHELL BUILTIN COMMANDS__ below).
134 ;__HOSTNAME__ : Automatically set to the name of the current host.
135 ;__HOSTTYPE__ : Automatically set to a string that uniquely describes the type of machine on which __bash__ is executing. The default is system-dependent.
136 ;__OSTYPE__ : Automatically set to a string that describes the operating system on which __bash__ is executing. The default is system-dependent.
137 ;__MACHTYPE__ : Automatically set to a string that fully describes the system type on which __bash__ is executing, in the standard GNU ''cpu-company-system'' format. The default is system-dependent.
138 ;__SHELLOPTS__ : A colon-separated list of enabled shell options. Each word in the list is a valid argument for the __-o__ option to the __set__ builtin command (see __SHELL BUILTIN COMMANDS__ below). The options appearing in __SHELLOPTS__ are those reported as ''on'' by __set -o__. If this variable is in the environment when __bash__ starts up, each shell option in the list will be enabled before reading any startup files. This variable is read-only.
139 ;__COMP_WORDS__ : An array variable (see __Arrays__ below) consisting of the individual words in the current command line. This variable is available only in shell functions invoked by the programmable completion facilities (see __Programmable Completion__ below).
140 ;__COMP_CWORD__ : An index into __${COMP_WORDS}__ of the word containing the current cursor position. This variable is available only in shell functions invoked by the programmable completion facilities (see __Programmable Completion__ below).
141 ;__COMP_LINE__ : The current command line. This variable is available only in shell functions and external commands invoked by the programmable completion facilities (see __Programmable Completion__ below).
142 ;__COMP_POINT__ : The index of the current cursor position relative to the beginning of the current command. If the current cursor position is at the end of the current command, the value of this variable is equal to __${#COMP_LINE}__. This variable is available only in shell functions and external commands invoked by the programmable completion facilities (see __Programmable Completion__ below).
143
144
145
146 The following variables are used by the shell. In some cases, __bash__ assigns a default value to a variable; these cases are noted below.
147
148
149
150 ;__IFS__ : The ''Internal Field Separator'' that is used for word splitting after expansion and to split lines into words with the __read__ builtin command. The default value is ``<space><tab><newline>".
151 ;__PATH__ : The search path for commands. It is a colon-separated list of directories in which the shell looks for commands (see __COMMAND EXECUTION__ below). The default path is system-dependent, and is set by the administrator who installs __bash__ . A common value is
152 "/usr/gnu/bin:/usr/local/bin:/usr/ucb:/bin:/usr/bin:.".
153 ;__HOME__ : The home directory of the current user; the default argument for the __cd__ builtin command. The value of this variable is also used when performing tilde expansion.
154 ;__CDPATH__ : The search path for the __cd__ command. This is a colon-separated list of directories in which the shell looks for destination directories specified by the __cd__ command. A sample value is ".:~:/usr".
155 ;__BASH_ENV__ : If this parameter is set when __bash__ is executing a shell script, its value is interpreted as a filename containing commands to initialize the shell, as in ''~/.bashrc'' . The value of __BASH_ENV__ is subjected to parameter expansion, command substitution, and arithmetic expansion before being interpreted as a file name. __PATH__ is not used to search for the resultant file name.
156 ;__MAIL__ : If this parameter is set to a file name and the __MAILPATH__ variable is not set, __bash__ informs the user of the arrival of mail in the specified file.
157 ;__MAILCHECK__ : Specifies how often (in seconds) __bash__ checks for mail. The default is 60 seconds. When it is time to check for mail, the shell does so before displaying the primary prompt. 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.
158 ;__MAILPATH__ : A colon-separated list of file names 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 `?'. When used in the text of the message, __$___ expands to the name of the current mailfile. Example:
159
160 __MAILPATH__='/var/mail/bfox?"You have mail":~/shell-mail?"$_ has mail!"'
161 __Bash__ supplies a default value for this variable, but the location of the user mail files that it uses is system dependent (e.g., /var/mail/__$USER__).
162
163 ;__PS1__ : The value of this parameter is expanded (see __PROMPTING__ below) and used as the primary prompt string. The default value is ``__\s-\v\$ __".
164 ;__PS2__ : The value of this parameter is expanded as with __PS1__ and used as the secondary prompt string. The default is ``__> __".
165 ;__PS3__ : The value of this parameter is used as the prompt for the __select__ command (see __SHELL GRAMMAR__ above).
166 ;__PS4__ : The value of this parameter is expanded as with __PS1__ and the value is printed before each command __bash__ displays during an execution trace. The first character of __PS4__ is replicated multiple times, as necessary, to indicate multiple levels of indirection. The default is "__+ __".
167 ;__TIMEFORMAT__ : The value of this parameter is used as a format string specifying how the timing information for pipelines prefixed with the __time__ reserved word should be displayed. The __%__ character introduces an escape sequence that is expanded to a time value or other information. The escape sequences and their meanings are as follows; the braces denote optional portions.
168
169
170
171
172 ;__%%__ : A literal __%__.
173 ;__%[[''p''][[l]R__ : The elapsed time in seconds.
174 ;__%[[''p''][[l]U__ : The number of CPU seconds spent in user mode.
175 ;__%[[''p''][[l]S__ : The number of CPU seconds spent in system mode.
176 ;__%P__ : The CPU percentage, computed as (%U + %S) / %R.
177
178
179 ;: The optional ''p'' is a digit specifying the ''precision'', the number of fractional digits after a decimal point. A value of 0 causes no decimal point or fraction to be output. At most three places after the decimal point may be specified; values of ''p'' greater than 3 are changed to 3. If ''p'' is not specified, the value 3 is used.
180 ;: The optional __l__ specifies a longer format, including minutes, of the form ''MM''m''SS''.''FF''s. The value of ''p'' determines whether or not the fraction is included.
181 ;: If this variable is not set, __bash__ acts as if it had the value __$'\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS'__. If the value is null, no timing information is displayed. A trailing newline is added when the format string is displayed.
182 ;__HISTSIZE__ : The number of commands to remember in the command history (see __HISTORY__ below). The default value is 500.
183 ;__HISTFILE__ : The name of the file in which command history is saved (see __HISTORY__ below). The default value is ''~/.bash_history''. If unset, the command history is not saved when an interactive shell exits.
184 ;__HISTFILESIZE__ : The maximum number of lines contained in the history file. When this variable is assigned a value, the history file is truncated, if necessary, to contain no more than that number of lines. The default value is 500. The history file is also truncated to this size after writing it when an interactive shell exits.
185 ;__OPTERR__ : If set to the value 1, __bash__ displays error messages generated by the __getopts__ builtin command (see __SHELL BUILTIN COMMANDS__ below). __OPTERR__ is initialized to 1 each time the shell is invoked or a shell script is executed.
186 ;__LANG__ : Used to determine the locale category for any category not specifically selected with a variable starting with __LC___.
187 ;__LC_ALL__ : This variable overrides the value of __LANG__ and any other __LC___ variable specifying a locale category.
188 ;__LC_COLLATE__ : This variable determines the collation order used when sorting the results of pathname expansion, and determines the behavior of range expressions, equivalence classes, and collating sequences within pathname expansion and pattern matching.
189 ;__LC_CTYPE__ : This variable determines the interpretation of characters and the behavior of character classes within pathname expansion and pattern matching.
190 ;__LC_MESSAGES__ : This variable determines the locale used to translate double-quoted strings preceded by a __$__.
191 ;__LC_NUMERIC__ : This variable determines the locale category used for number formatting.
192 ;__LINES__ : Used by the __select__ builtin command to determine the column length for printing selection lists. Automatically set upon receipt of a SIGWINCH.
193 ;__COLUMNS__ : Used by the __select__ builtin command to determine the terminal width when printing selection lists. Automatically set upon receipt of a SIGWINCH.
194 ;__PROMPT_COMMAND__ : If set, the value is executed as a command prior to issuing each primary prompt.
195 ;__IGNOREEOF__ : Controls the action of an interactive shell on receipt of an __EOF__ character as the sole input. If set, the value is the number of consecutive __EOF__ characters which must be typed as the first characters on an input line before __bash__ exits. If the variable exists but does not have a numeric value, or has no value, the default value is 10. If it does not exist, __EOF__ signifies the end of input to the shell.
196 ;__TMOUT__ : If set to a value greater than zero, the value is interpreted as the number of seconds to wait for input after issuing the primary prompt. __Bash__ terminates after waiting for that number of seconds if input does not arrive.
197 ;__FCEDIT__ : The default editor for the __fc__ builtin command.
198 ;__FIGNORE__ : A colon-separated list of suffixes to ignore when performing filename completion (see __READLINE__ below). A filename whose suffix matches one of the entries in __FIGNORE__ is excluded from the list of matched filenames. A sample value is ".o:~".
199 ;__GLOBIGNORE__ : A colon-separated list of patterns defining the set of filenames to be ignored by pathname expansion. If a filename matched by a pathname expansion pattern also matches one of the patterns in __GLOBIGNORE__ , it is removed from the list of matches.
200 ;__INPUTRC__ : The filename for the __readline__ startup file, overriding the default of ~/.inputrc (see __READLINE__ below).
201 ;__HISTCONTROL__ : If set to a value of ''ignorespace'' , lines which begin with a __space__ character are not entered on the history list. If set to a value of ''ignoredups'' , lines matching the last history line are not entered. A value of ''ignoreboth'' combines the two options. If unset, or if set to any other value than those above, all lines read by the parser are saved on the history list, subject to the value of __HISTIGNORE__ . This variable's function is superseded by __HISTIGNORE__ . The second and subsequent lines of a multi-line compound command are not tested, and are added to the history regardless of the value of __HISTCONTROL__ .
202 ;__HISTIGNORE__ : A colon-separated list of patterns used to decide which command lines should be saved on the history list. Each pattern is anchored at the beginning of the line and must match the complete line (no implicit `__*__' is appended). Each pattern is tested against the line after the checks specified by __HISTCONTROL__ are applied. In addition to the normal shell pattern matching characters, `__&__' matches the previous history line. `__&__' may be escaped using a backslash; the backslash is removed before attempting a match. The second and subsequent lines of a multi-line compound command are not tested, and are added to the history regardless of the value of __HISTIGNORE__ .
203 ;__histchars__ : The two or three characters which control history expansion and tokenization (see __HISTORY EXPANSION__ below). The first character is the ''history expansion'' character, the character which signals the start of a history expansion, normally `__!__'. The second character is the ''quick substitution'' character, which is used as shorthand for re-running the previous command entered, substituting one string for another in the command. The default is `__^__'. The optional third character is the character which indicates that the remainder of the line is a comment when found as the first character of a word, normally `__#__'. The history comment character causes history substitution to be skipped for the remaining words on the line. It does not necessarily cause the shell parser to treat the rest of the line as a comment.
204 ;__HOSTFILE__ : Contains the name of a file in the same format as /etc/hosts that should be read when the shell needs to complete a hostname. The list of possible hostname completions may be changed while the shell is running; the next time hostname completion is attempted after the value is changed, __bash__ adds the contents of the new file to the existing list. If __HOSTFILE__ is set, but has no value, __bash__ attempts to read /etc/hosts to obtain the list of possible hostname completions. When __HOSTFILE__ is unset, the hostname list is cleared.
205 ;__auto_resume__ : This variable controls how the shell interacts with the user and job control. If this variable is set, single word simple commands without redirections are treated as candidates for resumption of an existing stopped job. There is no ambiguity allowed; if there is more than one job beginning with the string typed, the job most recently accessed is selected. The ''name'' of a stopped job, in this context, is the command line used to start it. If set to the value ''exact'' , the string supplied must match the name of a stopped job exactly; if set to ''substring'' , the string supplied needs to match a substring of the name of a stopped job. The ''substring'' value provides functionality analogous to the __%?__ job identifier (see __JOB CONTROL__ below). If set to any other value, the supplied string must be a prefix of a stopped job's name; this provides functionality analogous to the __%__ job identifier.
206 ;__COMPREPLY__ : An array variable from which __bash__ reads the possible completions generated by a shell function invoked by the programmable completion facility (see __Programmable Completion__ below).
207
208
209
210 !Arrays
211 __Bash__ provides one-dimensional array variables. Any variable may be used as an array; the __declare__ builtin will explicitly declare an array. There is no maximum limit on the size of an array, nor any requirement that members be indexed or assigned contiguously. Arrays are indexed using integers and are zero-based.
212
213 An array is created automatically if any variable is assigned to using the syntax ''name''[[''subscript'']=''value''. The ''subscript'' is treated as an arithmetic expression that must evaluate to a number greater than or equal to zero. To explicitly declare an array, use __declare -a ''name''__ (see __SHELL BUILTIN COMMANDS__ below). __declare -a ''name''[[''subscript'']__ is also accepted; the ''subscript'' is ignored. Attributes may be specified for an array variable using the __declare__ and __readonly__ builtins. Each attribute applies to all members of an array.
214
215 Arrays are assigned to using compound assignments of the form ''name''=__(__value''1'' ... value''n''__)__, where each ''value'' is of the form [[''subscript'']=''string''. Only ''string'' is required. 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 to by the statement plus one. Indexing starts at zero. This syntax is also accepted by the __declare__ builtin. Individual array elements may be assigned to using the ''name''[[''subscript'']=''value'' syntax introduced above.
216
217 Any element of an array may be referenced using ${''name''[[''subscript'']}. The braces are required to avoid conflicts with pathname expansion. If ''subscript'' is __@__ or __*__, the word expands to all members of ''name''. These subscripts differ only when the word appears within double quotes. If the word is double-quoted, ${''name''[[*]} expands to a single word with the value of each array member separated by the first character of the __IFS__ special variable, and ${''name''[[@]} expands each element of ''name'' to a separate word. When there are no array members, ${''name''[[@]} expands to nothing. This is analogous to the expansion of the special parameters __*__ and __@__ (see __Special Parameters__ above). ${#''name''[[''subscript'']} expands to the length of ${''name''[[''subscript'']}. If ''subscript'' is __*__ or __@__, the expansion is the number of elements in the array. Referencing an array variable without a subscript is equivalent to referencing element zero.
218
219 The __unset__ builtin is used to destroy arrays. __unset__ ''name''[[''subscript''] destroys the array element at index ''subscript''. __unset__ ''name'', where ''name'' is an array, or __unset__ ''name''[[''subscript''], where ''subscript'' is __*__ or __@__, removes the entire array.
220
221 The __declare__ , __local__ , and __readonly__ builtins each accept a __-a__ option to specify an array. The __read__ builtin accepts a __-a__ option to assign a list of words read from the standard input to an array. The __set__ and __declare__ builtins display array values in a way that allows them to be reused as assignments.
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.