| 1 | \"
|
|---|
| 2 | .\" MAN PAGE COMMENTS to
|
|---|
| 3 | .\"
|
|---|
| 4 | .\" Chet Ramey
|
|---|
| 5 | .\" Information Network Services
|
|---|
| 6 | .\" Case Western Reserve University
|
|---|
| 7 | .\" [email protected]
|
|---|
| 8 | .\"
|
|---|
| 9 | .\" Last Change: Sat Aug 27 13:28:44 EDT 2005
|
|---|
| 10 | .\"
|
|---|
| 11 | .\" bash_builtins, strip all but Built-Ins section
|
|---|
| 12 | .if \n(zZ=1 .ig zZ
|
|---|
| 13 | .if \n(zY=1 .ig zY
|
|---|
| 14 | .TH BASH 1 "2005 Aug 27" "GNU Bash-3.1-beta1"
|
|---|
| 15 | .\"
|
|---|
| 16 | .\" There's some problem with having a `@'
|
|---|
| 17 | .\" in a tagged paragraph with the BSD man macros.
|
|---|
| 18 | .\" It has to do with `@' appearing in the }1 macro.
|
|---|
| 19 | .\" This is a problem on 4.3 BSD and Ultrix, but Sun
|
|---|
| 20 | .\" appears to have fixed it.
|
|---|
| 21 | .\" If you're seeing the characters
|
|---|
| 22 | .\" `@u-3p' appearing before the lines reading
|
|---|
| 23 | .\" `possible-hostname-completions
|
|---|
| 24 | .\" and `complete-hostname' down in READLINE,
|
|---|
| 25 | .\" then uncomment this redefinition.
|
|---|
| 26 | .\"
|
|---|
| 27 | .de }1
|
|---|
| 28 | .ds ]X \&\\*(]B\\
|
|---|
| 29 | .nr )E 0
|
|---|
| 30 | .if !"\\$1"" .nr )I \\$1n
|
|---|
| 31 | .}f
|
|---|
| 32 | .ll \\n(LLu
|
|---|
| 33 | .in \\n()Ru+\\n(INu+\\n()Iu
|
|---|
| 34 | .ti \\n(INu
|
|---|
| 35 | .ie !\\n()Iu+\\n()Ru-\w\\*(]Xu-3p \{\\*(]X
|
|---|
| 36 | .br\}
|
|---|
| 37 | .el \\*(]X\h|\\n()Iu+\\n()Ru\c
|
|---|
| 38 | .}f
|
|---|
| 39 | ..
|
|---|
| 40 | .\"
|
|---|
| 41 | .\" File Name macro. This used to be `.PN', for Path Name,
|
|---|
| 42 | .\" but Sun doesn't seem to like that very much.
|
|---|
| 43 | .\"
|
|---|
| 44 | .de FN
|
|---|
| 45 | \fI\|\\$1\|\fP
|
|---|
| 46 | ..
|
|---|
| 47 | .SH NAME
|
|---|
| 48 | bash \- GNU Bourne-Again SHell
|
|---|
| 49 | .SH SYNOPSIS
|
|---|
| 50 | .B bash
|
|---|
| 51 | [options]
|
|---|
| 52 | [file]
|
|---|
| 53 | .SH COPYRIGHT
|
|---|
| 54 | .if n Bash is Copyright (C) 1989-2005 by the Free Software Foundation, Inc.
|
|---|
| 55 | .if t Bash is Copyright \(co 1989-2005 by the Free Software Foundation, Inc.
|
|---|
| 56 | .SH DESCRIPTION
|
|---|
| 57 | .B Bash
|
|---|
| 58 | is an \fBsh\fR-compatible command language interpreter that
|
|---|
| 59 | executes commands read from the standard input or from a file.
|
|---|
| 60 | .B Bash
|
|---|
| 61 | also incorporates useful features from the \fIKorn\fP and \fIC\fP
|
|---|
| 62 | shells (\fBksh\fP and \fBcsh\fP).
|
|---|
| 63 | .PP
|
|---|
| 64 | .B Bash
|
|---|
| 65 | is intended to be a conformant implementation of the IEEE
|
|---|
| 66 | POSIX Shell and Tools specification (IEEE Working Group 1003\.2).
|
|---|
| 67 | .B Bash
|
|---|
| 68 | can be configured to be POSIX-conformant by default.
|
|---|
| 69 | .SH OPTIONS
|
|---|
| 70 | In addition to the single-character shell options documented in the
|
|---|
| 71 | description of the \fBset\fR builtin command, \fBbash\fR
|
|---|
| 72 | interprets the following options when it is invoked:
|
|---|
| 73 | .PP
|
|---|
| 74 | .PD 0
|
|---|
| 75 | .TP 10
|
|---|
| 76 | .BI \-c "\| string\^"
|
|---|
| 77 | If the
|
|---|
| 78 | .B \-c
|
|---|
| 79 | option is present, then commands are read from
|
|---|
| 80 | .IR string .
|
|---|
| 81 | If there are arguments after the
|
|---|
| 82 | .IR string ,
|
|---|
| 83 | they are assigned to the positional parameters, starting with
|
|---|
| 84 | .BR $0 .
|
|---|
| 85 | .TP
|
|---|
| 86 | .B \-i
|
|---|
| 87 | If the
|
|---|
| 88 | .B \-i
|
|---|
| 89 | option is present, the shell is
|
|---|
| 90 | .IR interactive .
|
|---|
| 91 | .TP
|
|---|
| 92 | .B \-l
|
|---|
| 93 | Make
|
|---|
| 94 | .B bash
|
|---|
| 95 | act as if it had been invoked as a login shell (see
|
|---|
| 96 | .SM
|
|---|
| 97 | .B INVOCATION
|
|---|
| 98 | below).
|
|---|
| 99 | .TP
|
|---|
| 100 | .B \-r
|
|---|
| 101 | If the
|
|---|
| 102 | .B \-r
|
|---|
| 103 | option is present, the shell becomes
|
|---|
| 104 | .I restricted
|
|---|
| 105 | (see
|
|---|
| 106 | .SM
|
|---|
| 107 | .B "RESTRICTED SHELL"
|
|---|
| 108 | below).
|
|---|
| 109 | .TP
|
|---|
| 110 | .B \-s
|
|---|
| 111 | If the
|
|---|
| 112 | .B \-s
|
|---|
| 113 | option is present, or if no arguments remain after option
|
|---|
| 114 | processing, then commands are read from the standard input.
|
|---|
| 115 | This option allows the positional parameters to be set
|
|---|
| 116 | when invoking an interactive shell.
|
|---|
| 117 | .TP
|
|---|
| 118 | .B \-D
|
|---|
| 119 | A list of all double-quoted strings preceded by \fB$\fP
|
|---|
| 120 | is printed on the standard output.
|
|---|
| 121 | These are the strings that
|
|---|
| 122 | are subject to language translation when the current locale
|
|---|
| 123 | is not \fBC\fP or \fBPOSIX\fP.
|
|---|
| 124 | This implies the \fB\-n\fP option; no commands will be executed.
|
|---|
| 125 | .TP
|
|---|
| 126 | .B [\-+]O [\fIshopt_option\fP]
|
|---|
| 127 | \fIshopt_option\fP is one of the shell options accepted by the
|
|---|
| 128 | \fBshopt\fP builtin (see
|
|---|
| 129 | .SM
|
|---|
| 130 | .B SHELL BUILTIN COMMANDS
|
|---|
| 131 | below).
|
|---|
| 132 | If \fIshopt_option\fP is present, \fB\-O\fP sets the value of that option;
|
|---|
| 133 | \fB+O\fP unsets it.
|
|---|
| 134 | If \fIshopt_option\fP is not supplied, the names and values of the shell
|
|---|
| 135 | options accepted by \fBshopt\fP are printed on the standard output.
|
|---|
| 136 | If the invocation option is \fB+O\fP, the output is displayed in a format
|
|---|
| 137 | that may be reused as input.
|
|---|
| 138 | .TP
|
|---|
| 139 | .B \-\-
|
|---|
| 140 | A
|
|---|
| 141 | .B \-\-
|
|---|
| 142 | signals the end of options and disables further option processing.
|
|---|
| 143 | Any arguments after the
|
|---|
| 144 | .B \-\-
|
|---|
| 145 | are treated as filenames and arguments. An argument of
|
|---|
| 146 | .B \-
|
|---|
| 147 | is equivalent to \fB\-\-\fP.
|
|---|
| 148 | .PD
|
|---|
| 149 | .PP
|
|---|
| 150 | .B Bash
|
|---|
| 151 | also interprets a number of multi-character options.
|
|---|
| 152 | These options must appear on the command line before the
|
|---|
| 153 | single-character options to be recognized.
|
|---|
| 154 | .PP
|
|---|
| 155 | .PD 0
|
|---|
| 156 | .TP
|
|---|
| 157 | .B \-\-debugger
|
|---|
| 158 | Arrange for the debugger profile to be executed before the shell
|
|---|
| 159 | starts.
|
|---|
| 160 | Turns on extended debugging mode (see the description of the
|
|---|
| 161 | .B extdebug
|
|---|
| 162 | option to the
|
|---|
| 163 | .B shopt
|
|---|
| 164 | builtin below)
|
|---|
| 165 | and shell function tracing (see the description of the
|
|---|
| 166 | \fB\-o functrace\fP option to the
|
|---|
| 167 | .B set
|
|---|
| 168 | builtin below).
|
|---|
| 169 | .TP
|
|---|
| 170 | .B \-\-dump\-po\-strings
|
|---|
| 171 | Equivalent to \fB\-D\fP, but the output is in the GNU \fIgettext\fP
|
|---|
| 172 | \fBpo\fP (portable object) file format.
|
|---|
| 173 | .TP
|
|---|
| 174 | .B \-\-dump\-strings
|
|---|
| 175 | Equivalent to \fB\-D\fP.
|
|---|
| 176 | .TP
|
|---|
| 177 | .B \-\-help
|
|---|
| 178 | Display a usage message on standard output and exit successfully.
|
|---|
| 179 | .TP
|
|---|
| 180 | \fB\-\-init\-file\fP \fIfile\fP
|
|---|
| 181 | .PD 0
|
|---|
| 182 | .TP
|
|---|
| 183 | \fB\-\-rcfile\fP \fIfile\fP
|
|---|
| 184 | .PD
|
|---|
| 185 | Execute commands from
|
|---|
| 186 | .I file
|
|---|
| 187 | instead of the standard personal initialization file
|
|---|
| 188 | .I ~/.bashrc
|
|---|
| 189 | if the shell is interactive (see
|
|---|
| 190 | .SM
|
|---|
| 191 | .B INVOCATION
|
|---|
| 192 | below).
|
|---|
| 193 | .TP
|
|---|
| 194 | .B \-\-login
|
|---|
| 195 | Equivalent to \fB\-l\fP.
|
|---|
| 196 | .TP
|
|---|
| 197 | .B \-\-noediting
|
|---|
| 198 | Do not use the GNU
|
|---|
| 199 | .B readline
|
|---|
| 200 | library to read command lines when the shell is interactive.
|
|---|
| 201 | .TP
|
|---|
| 202 | .B \-\-noprofile
|
|---|
| 203 | Do not read either the system-wide startup file
|
|---|
| 204 | .FN /etc/profile
|
|---|
| 205 | or any of the personal initialization files
|
|---|
| 206 | .IR ~/.bash_profile ,
|
|---|
| 207 | .IR ~/.bash_login ,
|
|---|
| 208 | or
|
|---|
| 209 | .IR ~/.profile .
|
|---|
| 210 | By default,
|
|---|
| 211 | .B bash
|
|---|
| 212 | reads these files when it is invoked as a login shell (see
|
|---|
| 213 | .SM
|
|---|
| 214 | .B INVOCATION
|
|---|
| 215 | below).
|
|---|
| 216 | .TP
|
|---|
| 217 | .B \-\-norc
|
|---|
| 218 | Do not read and execute the personal initialization file
|
|---|
| 219 | .I ~/.bashrc
|
|---|
| 220 | if the shell is interactive.
|
|---|
| 221 | This option is on by default if the shell is invoked as
|
|---|
| 222 | .BR sh .
|
|---|
| 223 | .TP
|
|---|
| 224 | .B \-\-posix
|
|---|
| 225 | Change the behavior of \fBbash\fP where the default operation differs
|
|---|
| 226 | from the POSIX 1003.2 standard to match the standard (\fIposix mode\fP).
|
|---|
| 227 | .TP
|
|---|
| 228 | .B \-\-restricted
|
|---|
| 229 | The shell becomes restricted (see
|
|---|
| 230 | .SM
|
|---|
| 231 | .B "RESTRICTED SHELL"
|
|---|
| 232 | below).
|
|---|
| 233 | .TP
|
|---|
| 234 | .B \-\-verbose
|
|---|
| 235 | Equivalent to \fB\-v\fP.
|
|---|
| 236 | .TP
|
|---|
| 237 | .B \-\-version
|
|---|
| 238 | Show version information for this instance of
|
|---|
| 239 | .B bash
|
|---|
| 240 | on the standard output and exit successfully.
|
|---|
| 241 | .PD
|
|---|
| 242 | .SH ARGUMENTS
|
|---|
| 243 | If arguments remain after option processing, and neither the
|
|---|
| 244 | .B \-c
|
|---|
| 245 | nor the
|
|---|
| 246 | .B \-s
|
|---|
| 247 | option has been supplied, the first argument is assumed to
|
|---|
| 248 | be the name of a file containing shell commands.
|
|---|
| 249 | If
|
|---|
| 250 | .B bash
|
|---|
| 251 | is invoked in this fashion,
|
|---|
| 252 | .B $0
|
|---|
| 253 | is set to the name of the file, and the positional parameters
|
|---|
| 254 | are set to the remaining arguments.
|
|---|
| 255 | .B Bash
|
|---|
| 256 | reads and executes commands from this file, then exits.
|
|---|
| 257 | \fBBash\fP's exit status is the exit status of the last command
|
|---|
| 258 | executed in the script.
|
|---|
| 259 | If no commands are executed, the exit status is 0.
|
|---|
| 260 | An attempt is first made to open the file in the current directory, and,
|
|---|
| 261 | if no file is found, then the shell searches the directories in
|
|---|
| 262 | .SM
|
|---|
| 263 | .B PATH
|
|---|
| 264 | for the script.
|
|---|
| 265 | .SH INVOCATION
|
|---|
| 266 | A \fIlogin shell\fP is one whose first character of argument zero is a
|
|---|
| 267 | .BR \- ,
|
|---|
| 268 | or one started with the
|
|---|
| 269 | .B \-\-login
|
|---|
| 270 | option.
|
|---|
| 271 | .PP
|
|---|
| 272 | An \fIinteractive\fP shell is one started without non-option arguments
|
|---|
| 273 | and without the
|
|---|
| 274 | .B \-c
|
|---|
| 275 | option
|
|---|
| 276 | whose standard input and error are
|
|---|
| 277 | both connected to terminals (as determined by
|
|---|
| 278 | .IR isatty (3)),
|
|---|
| 279 | or one started with the
|
|---|
| 280 | .B \-i
|
|---|
| 281 | option.
|
|---|
| 282 | .SM
|
|---|
| 283 | .B PS1
|
|---|
| 284 | is set and
|
|---|
| 285 | .B $\-
|
|---|
| 286 | includes
|
|---|
| 287 | .B i
|
|---|
| 288 | if
|
|---|
| 289 | .B bash
|
|---|
| 290 | is interactive,
|
|---|
| 291 | allowing a shell script or a startup file to test this state.
|
|---|
| 292 | .PP
|
|---|
| 293 | The following paragraphs describe how
|
|---|
| 294 | .B bash
|
|---|
| 295 | executes its startup files.
|
|---|
| 296 | If any of the files exist but cannot be read,
|
|---|
| 297 | .B bash
|
|---|
| 298 | reports an error.
|
|---|
| 299 | Tildes are expanded in file names as described below under
|
|---|
| 300 | .B "Tilde Expansion"
|
|---|
| 301 | in the
|
|---|
| 302 | .SM
|
|---|
| 303 | .B EXPANSION
|
|---|
| 304 | section.
|
|---|
| 305 | .PP
|
|---|
| 306 | When
|
|---|
| 307 | .B bash
|
|---|
| 308 | is invoked as an interactive login shell, or as a non-interactive shell
|
|---|
| 309 | with the \fB\-\-login\fP option, it first reads and
|
|---|
| 310 | executes commands from the file \fI/etc/profile\fP, if that
|
|---|
| 311 | file exists.
|
|---|
| 312 | After reading that file, it looks for \fI~/.bash_profile\fP,
|
|---|
| 313 | \fI~/.bash_login\fP, and \fI~/.profile\fP, in that order, and reads
|
|---|
| 314 | and executes commands from the first one that exists and is readable.
|
|---|
| 315 | The
|
|---|
| 316 | .B \-\-noprofile
|
|---|
| 317 | option may be used when the shell is started to inhibit this behavior.
|
|---|
| 318 | .PP
|
|---|
| 319 | When a login shell exits,
|
|---|
| 320 | .B bash
|
|---|
| 321 | reads and executes commands from the file \fI~/.bash_logout\fP, if it
|
|---|
| 322 | exists.
|
|---|
| 323 | .PP
|
|---|
| 324 | When an interactive shell that is not a login shell is started,
|
|---|
| 325 | .B bash
|
|---|
| 326 | reads and executes commands from \fI~/.bashrc\fP, if that file exists.
|
|---|
| 327 | This may be inhibited by using the
|
|---|
| 328 | .B \-\-norc
|
|---|
| 329 | option.
|
|---|
| 330 | The \fB\-\-rcfile\fP \fIfile\fP option will force
|
|---|
| 331 | .B bash
|
|---|
| 332 | to read and execute commands from \fIfile\fP instead of \fI~/.bashrc\fP.
|
|---|
| 333 | .PP
|
|---|
| 334 | When
|
|---|
| 335 | .B bash
|
|---|
| 336 | is started non-interactively, to run a shell script, for example, it
|
|---|
| 337 | looks for the variable
|
|---|
| 338 | .SM
|
|---|
| 339 | .B BASH_ENV
|
|---|
| 340 | in the environment, expands its value if it appears there, and uses the
|
|---|
| 341 | expanded value as the name of a file to read and execute.
|
|---|
| 342 | .B Bash
|
|---|
| 343 | behaves as if the following command were executed:
|
|---|
| 344 | .sp .5
|
|---|
| 345 | .RS
|
|---|
| 346 | .if t \f(CWif [ \-n "$BASH_ENV" ]; then . "$BASH_ENV"; fi\fP
|
|---|
| 347 | .if n if [ \-n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
|
|---|
| 348 | .RE
|
|---|
| 349 | .sp .5
|
|---|
| 350 | but the value of the
|
|---|
| 351 | .SM
|
|---|
| 352 | .B PATH
|
|---|
| 353 | variable is not used to search for the file name.
|
|---|
| 354 | .PP
|
|---|
| 355 | If
|
|---|
| 356 | .B bash
|
|---|
| 357 | is invoked with the name
|
|---|
| 358 | .BR sh ,
|
|---|
| 359 | it tries to mimic the startup behavior of historical versions of
|
|---|
| 360 | .B sh
|
|---|
| 361 | as closely as possible,
|
|---|
| 362 | while conforming to the POSIX standard as well.
|
|---|
| 363 | When invoked as an interactive login shell, or a non-interactive
|
|---|
| 364 | shell with the \fB\-\-login\fP option, it first attempts to
|
|---|
| 365 | read and execute commands from
|
|---|
| 366 | .I /etc/profile
|
|---|
| 367 | and
|
|---|
| 368 | .IR ~/.profile ,
|
|---|
| 369 | in that order.
|
|---|
| 370 | The
|
|---|
| 371 | .B \-\-noprofile
|
|---|
| 372 | option may be used to inhibit this behavior.
|
|---|
| 373 | When invoked as an interactive shell with the name
|
|---|
| 374 | .BR sh ,
|
|---|
| 375 | .B bash
|
|---|
| 376 | looks for the variable
|
|---|
| 377 | .SM
|
|---|
| 378 | .BR ENV ,
|
|---|
| 379 | expands its value if it is defined, and uses the
|
|---|
| 380 | expanded value as the name of a file to read and execute.
|
|---|
| 381 | Since a shell invoked as
|
|---|
| 382 | .B sh
|
|---|
| 383 | does not attempt to read and execute commands from any other startup
|
|---|
| 384 | files, the
|
|---|
| 385 | .B \-\-rcfile
|
|---|
| 386 | option has no effect.
|
|---|
| 387 | A non-interactive shell invoked with the name
|
|---|
| 388 | .B sh
|
|---|
| 389 | does not attempt to read any other startup files.
|
|---|
| 390 | When invoked as
|
|---|
| 391 | .BR sh ,
|
|---|
| 392 | .B bash
|
|---|
| 393 | enters
|
|---|
| 394 | .I posix
|
|---|
| 395 | mode after the startup files are read.
|
|---|
| 396 | .PP
|
|---|
| 397 | When
|
|---|
| 398 | .B bash
|
|---|
| 399 | is started in
|
|---|
| 400 | .I posix
|
|---|
| 401 | mode, as with the
|
|---|
| 402 | .B \-\-posix
|
|---|
| 403 | command line option, it follows the POSIX standard for startup files.
|
|---|
| 404 | In this mode, interactive shells expand the
|
|---|
| 405 | .SM
|
|---|
| 406 | .B ENV
|
|---|
| 407 | variable and commands are read and executed from the file
|
|---|
| 408 | whose name is the expanded value.
|
|---|
| 409 | No other startup files are read.
|
|---|
| 410 | .PP
|
|---|
| 411 | .B Bash
|
|---|
| 412 | attempts to determine when it is being run by the remote shell
|
|---|
| 413 | daemon, usually \fIrshd\fP.
|
|---|
| 414 | If
|
|---|
| 415 | .B bash
|
|---|
| 416 | determines it is being run by \fIrshd\fP, it reads and executes
|
|---|
| 417 | commands from \fI~/.bashrc\fP, if that file exists and is readable.
|
|---|
| 418 | It will not do this if invoked as \fBsh\fP.
|
|---|
| 419 | The
|
|---|
| 420 | .B \-\-norc
|
|---|
| 421 | option may be used to inhibit this behavior, and the
|
|---|
| 422 | .B \-\-rcfile
|
|---|
| 423 | option may be used to force another file to be read, but
|
|---|
| 424 | \fIrshd\fP does not generally invoke the shell with those options
|
|---|
| 425 | or allow them to be specified.
|
|---|
| 426 | .PP
|
|---|
| 427 | If the shell is started with the effective user (group) id not equal to the
|
|---|
| 428 | real user (group) id, and the \fB\-p\fP option is not supplied, no startup
|
|---|
| 429 | files are read, shell functions are not inherited from the environment, the
|
|---|
| 430 | .SM
|
|---|
| 431 | .B SHELLOPTS
|
|---|
| 432 | variable, if it appears in the environment, is ignored,
|
|---|
| 433 | and the effective user id is set to the real user id.
|
|---|
| 434 | If the \fB\-p\fP option is supplied at invocation, the startup behavior is
|
|---|
| 435 | the same, but the effective user id is not reset.
|
|---|
| 436 | .SH DEFINITIONS
|
|---|
| 437 | .PP
|
|---|
| 438 | The following definitions are used throughout the rest of this
|
|---|
| 439 | document.
|
|---|
| 440 | .PD 0
|
|---|
| 441 | .TP
|
|---|
| 442 | .B blank
|
|---|
| 443 | A space or tab.
|
|---|
| 444 | .TP
|
|---|
| 445 | .B word
|
|---|
| 446 | A sequence of characters considered as a single unit by the shell.
|
|---|
| 447 | Also known as a
|
|---|
| 448 | .BR token .
|
|---|
| 449 | .TP
|
|---|
| 450 | .B name
|
|---|
| 451 | A
|
|---|
| 452 | .I word
|
|---|
| 453 | consisting only of alphanumeric characters and underscores, and
|
|---|
| 454 | beginning with an alphabetic character or an underscore. Also
|
|---|
| 455 | referred to as an
|
|---|
| 456 | .BR identifier .
|
|---|
| 457 | .TP
|
|---|
| 458 | .B metacharacter
|
|---|
| 459 | A character that, when unquoted, separates words. One of the following:
|
|---|
| 460 | .br
|
|---|
| 461 | .RS
|
|---|
| 462 | .PP
|
|---|
| 463 | .if t \fB| & ; ( ) < > space tab\fP
|
|---|
| 464 | .if n \fB| & ; ( ) < > space tab\fP
|
|---|
| 465 | .RE
|
|---|
| 466 | .PP
|
|---|
| 467 | .TP
|
|---|
| 468 | .B control operator
|
|---|
| 469 | A \fItoken\fP that performs a control function. It is one of the following
|
|---|
| 470 | symbols:
|
|---|
| 471 | .RS
|
|---|
| 472 | .PP
|
|---|
| 473 | .if t \fB\(bv\(bv & && ; ;; ( ) | <newline>\fP
|
|---|
| 474 | .if n \fB|| & && ; ;; ( ) | <newline>\fP
|
|---|
| 475 | .RE
|
|---|
| 476 | .PD
|
|---|
| 477 | .SH "RESERVED WORDS"
|
|---|
| 478 | \fIReserved words\fP are words that have a special meaning to the shell.
|
|---|
| 479 | The following words are recognized as reserved when unquoted and either
|
|---|
| 480 | the first word of a simple command (see
|
|---|
| 481 | .SM
|
|---|
| 482 | .B SHELL GRAMMAR
|
|---|
| 483 | below) or the third word of a
|
|---|
| 484 | .B case
|
|---|
| 485 | or
|
|---|
| 486 | .B for
|
|---|
| 487 | command:
|
|---|
| 488 | .if t .RS
|
|---|
| 489 | .PP
|
|---|
| 490 | .B
|
|---|
| 491 | .if n ! case do done elif else esac fi for function if in select then until while { } time [[ ]]
|
|---|
| 492 | .if t ! case do done elif else esac fi for function if in select then until while { } time [[ ]]
|
|---|
| 493 | .if t .RE
|
|---|
| 494 | .SH "SHELL GRAMMAR"
|
|---|
| 495 | .SS Simple Commands
|
|---|
| 496 | .PP
|
|---|
| 497 | A \fIsimple command\fP is a sequence of optional variable assignments
|
|---|
| 498 | followed by \fBblank\fP-separated words and redirections, and
|
|---|
| 499 | terminated by a \fIcontrol operator\fP. The first word
|
|---|
| 500 | specifies the command to be executed, and is passed as argument zero.
|
|---|
| 501 | The remaining words are passed as arguments to the invoked command.
|
|---|
| 502 | .PP
|
|---|
| 503 | The return value of a \fIsimple command\fP is its exit status, or
|
|---|
| 504 | 128+\fIn\^\fP if the command is terminated by signal
|
|---|
| 505 | .IR n .
|
|---|
| 506 | .SS Pipelines
|
|---|
| 507 | .PP
|
|---|
| 508 | A \fIpipeline\fP is a sequence of one or more commands separated by
|
|---|
| 509 | the character
|
|---|
| 510 | .BR | .
|
|---|
| 511 | The format for a pipeline is:
|
|---|
| 512 | .RS
|
|---|
| 513 | .PP
|
|---|
| 514 | [\fBtime\fP [\fB\-p\fP]] [ ! ] \fIcommand\fP [ \fB|\fP \fIcommand2\fP ... ]
|
|---|
| 515 | .RE
|
|---|
| 516 | .PP
|
|---|
| 517 | The standard output of
|
|---|
| 518 | .I command
|
|---|
| 519 | is connected via a pipe to the standard input of
|
|---|
| 520 | .IR command2 .
|
|---|
| 521 | This connection is performed before any redirections specified by the
|
|---|
| 522 | command (see
|
|---|
| 523 | .SM
|
|---|
| 524 | .B REDIRECTION
|
|---|
| 525 | below).
|
|---|
| 526 | .PP
|
|---|
| 527 | The return status of a pipeline is the exit status of the last
|
|---|
| 528 | command, unless the \fBpipefail\fP option is enabled.
|
|---|
| 529 | If \fBpipefail\fP is enabled, the pipeline's return status is the
|
|---|
| 530 | value of the last (rightmost) command to exit with a non-zero status,
|
|---|
| 531 | or zero if all commands exit successfully.
|
|---|
| 532 | If the reserved word
|
|---|
| 533 | .B !
|
|---|
| 534 | precedes a pipeline, the exit status of that pipeline is the logical
|
|---|
| 535 | negation of the exit status as described above.
|
|---|
| 536 | The shell waits for all commands in the pipeline to
|
|---|
| 537 | terminate before returning a value.
|
|---|
| 538 | .PP
|
|---|
| 539 | If the
|
|---|
| 540 | .B time
|
|---|
| 541 | reserved word precedes a pipeline, the elapsed as well as user and
|
|---|
| 542 | system time consumed by its execution are reported when the pipeline
|
|---|
| 543 | terminates.
|
|---|
| 544 | The \fB\-p\fP option changes the output format to that specified by POSIX.
|
|---|
| 545 | The
|
|---|
| 546 | .SM
|
|---|
| 547 | .B TIMEFORMAT
|
|---|
| 548 | variable may be set to a format string that specifies how the timing
|
|---|
| 549 | information should be displayed; see the description of
|
|---|
| 550 | .SM
|
|---|
| 551 | .B TIMEFORMAT
|
|---|
| 552 | under
|
|---|
| 553 | .B "Shell Variables"
|
|---|
| 554 | below.
|
|---|
| 555 | .PP
|
|---|
| 556 | Each command in a pipeline is executed as a separate process (i.e., in a
|
|---|
| 557 | subshell).
|
|---|
| 558 | .SS Lists
|
|---|
| 559 | .PP
|
|---|
| 560 | A \fIlist\fP is a sequence of one or more pipelines separated by one
|
|---|
| 561 | of the operators
|
|---|
| 562 | .BR ; ,
|
|---|
| 563 | .BR & ,
|
|---|
| 564 | .BR && ,
|
|---|
| 565 | or
|
|---|
| 566 | .BR \(bv\(bv ,
|
|---|
| 567 | and optionally terminated by one of
|
|---|
| 568 | .BR ; ,
|
|---|
| 569 | .BR & ,
|
|---|
| 570 | or
|
|---|
| 571 | .BR <newline> .
|
|---|
| 572 | .PP
|
|---|
| 573 | Of these list operators,
|
|---|
| 574 | .B &&
|
|---|
| 575 | and
|
|---|
| 576 | .B \(bv\(bv
|
|---|
| 577 | have equal precedence, followed by
|
|---|
| 578 | .B ;
|
|---|
| 579 | and
|
|---|
| 580 | .BR &,
|
|---|
| 581 | which have equal precedence.
|
|---|
| 582 | .PP
|
|---|
| 583 | A sequence of one or more newlines may appear in a \fIlist\fP instead
|
|---|
| 584 | of a semicolon to delimit commands.
|
|---|
| 585 | .PP
|
|---|
| 586 | If a command is terminated by the control operator
|
|---|
| 587 | .BR & ,
|
|---|
| 588 | the shell executes the command in the \fIbackground\fP
|
|---|
| 589 | in a subshell. The shell does not wait for the command to
|
|---|
| 590 | finish, and the return status is 0. Commands separated by a
|
|---|
| 591 | .B ;
|
|---|
| 592 | are executed sequentially; the shell waits for each
|
|---|
| 593 | command to terminate in turn. The return status is the
|
|---|
| 594 | exit status of the last command executed.
|
|---|
| 595 | .PP
|
|---|
| 596 | The control operators
|
|---|
| 597 | .B &&
|
|---|
| 598 | and
|
|---|
| 599 | .B \(bv\(bv
|
|---|
| 600 | denote AND lists and OR lists, respectively.
|
|---|
| 601 | An AND list has the form
|
|---|
| 602 | .RS
|
|---|
| 603 | .PP
|
|---|
| 604 | \fIcommand1\fP \fB&&\fP \fIcommand2\fP
|
|---|
| 605 | .RE
|
|---|
| 606 | .PP
|
|---|
| 607 | .I command2
|
|---|
| 608 | is executed if, and only if,
|
|---|
| 609 | .I command1
|
|---|
| 610 | returns an exit status of zero.
|
|---|
| 611 | .PP
|
|---|
| 612 | An OR list has the form
|
|---|
| 613 | .RS
|
|---|
| 614 | .PP
|
|---|
| 615 | \fIcommand1\fP \fB\(bv\(bv\fP \fIcommand2\fP
|
|---|
| 616 | .PP
|
|---|
| 617 | .RE
|
|---|
| 618 | .PP
|
|---|
| 619 | .I command2
|
|---|
| 620 | is executed if and only if
|
|---|
| 621 | .I command1
|
|---|
| 622 | returns a non-zero exit status. The return status of
|
|---|
| 623 | AND and OR lists is the exit status of the last command
|
|---|
| 624 | executed in the list.
|
|---|
| 625 | .SS Compound Commands
|
|---|
| 626 | .PP
|
|---|
| 627 | A \fIcompound command\fP is one of the following:
|
|---|
| 628 | .TP
|
|---|
| 629 | (\fIlist\fP)
|
|---|
| 630 | \fIlist\fP is executed in a subshell environment (see
|
|---|
| 631 | .SM
|
|---|
| 632 | \fBCOMMAND EXECUTION ENVIRONMENT\fP
|
|---|
| 633 | below).
|
|---|
| 634 | Variable assignments and builtin
|
|---|
| 635 | commands that affect the shell's environment do not remain in effect
|
|---|
| 636 | after the command completes. The return status is the exit status of
|
|---|
| 637 | \fIlist\fP.
|
|---|
| 638 | .TP
|
|---|
| 639 | { \fIlist\fP; }
|
|---|
| 640 | \fIlist\fP is simply executed in the current shell environment.
|
|---|
| 641 | \fIlist\fP must be terminated with a newline or semicolon.
|
|---|
| 642 | This is known as a \fIgroup command\fP.
|
|---|
| 643 | The return status is the exit status of
|
|---|
| 644 | \fIlist\fP.
|
|---|
| 645 | Note that unlike the metacharacters \fB(\fP and \fB)\fP, \fB{\fP and
|
|---|
| 646 | \fB}\fP are \fIreserved words\fP and must occur where a reserved
|
|---|
| 647 | word is permitted to be recognized. Since they do not cause a word
|
|---|
| 648 | break, they must be separated from \fIlist\fP by whitespace.
|
|---|
| 649 | .TP
|
|---|
| 650 | ((\fIexpression\fP))
|
|---|
| 651 | The \fIexpression\fP is evaluated according to the rules described
|
|---|
| 652 | below under
|
|---|
| 653 | .SM
|
|---|
| 654 | .BR "ARITHMETIC EVALUATION" .
|
|---|
| 655 | If the value of the expression is non-zero, the return status is 0;
|
|---|
| 656 | otherwise the return status is 1. This is exactly equivalent to
|
|---|
| 657 | \fBlet "\fIexpression\fP"\fR.
|
|---|
| 658 | .TP
|
|---|
| 659 | \fB[[\fP \fIexpression\fP \fB]]\fP
|
|---|
| 660 | Return a status of 0 or 1 depending on the evaluation of
|
|---|
| 661 | the conditional expression \fIexpression\fP.
|
|---|
| 662 | Expressions are composed of the primaries described below under
|
|---|
| 663 | .SM
|
|---|
| 664 | .BR "CONDITIONAL EXPRESSIONS" .
|
|---|
| 665 | Word splitting and pathname expansion are not performed on the words
|
|---|
| 666 | between the \fB[[\fP and \fB]]\fP; tilde expansion, parameter and
|
|---|
| 667 | variable expansion, arithmetic expansion, command substitution, process
|
|---|
| 668 | substitution, and quote removal are performed.
|
|---|
| 669 | Conditional operators such as \fB\-f\fP must be unquoted to be recognized
|
|---|
| 670 | as primaries.
|
|---|
| 671 | .if t .sp 0.5
|
|---|
| 672 | .if n .sp 1
|
|---|
| 673 | When the \fB==\fP and \fB!=\fP operators are used, the string to the
|
|---|
| 674 | right of the operator is considered a pattern and matched according
|
|---|
| 675 | to the rules described below under \fBPattern Matching\fP.
|
|---|
| 676 | If the shell option
|
|---|
| 677 | .B nocasematch
|
|---|
| 678 | is enabled, the match is performed without regard to the case
|
|---|
| 679 | of alphabetic characters.
|
|---|
| 680 | The return value is 0 if the string matches or does not match
|
|---|
| 681 | the pattern, respectively, and 1 otherwise.
|
|---|
| 682 | Any part of the pattern may be quoted to force it to be matched as a
|
|---|
| 683 | string.
|
|---|
| 684 | .if t .sp 0.5
|
|---|
| 685 | .if n .sp 1
|
|---|
| 686 | An additional binary operator, \fB=~\fP, is available, with the same
|
|---|
| 687 | precedence as \fB==\fP and \fB!=\fP.
|
|---|
| 688 | When it is used, the string to the right of the operator is considered
|
|---|
| 689 | an extended regular expression and matched accordingly (as in \fIregex\fP(3)).
|
|---|
| 690 | The return value is 0 if the string matches
|
|---|
| 691 | the pattern, and 1 otherwise.
|
|---|
| 692 | If the regular expression is syntactically incorrect, the conditional
|
|---|
| 693 | expression's return value is 2.
|
|---|
| 694 | If the shell option
|
|---|
| 695 | .B nocasematch
|
|---|
| 696 | is enabled, the match is performed without regard to the case
|
|---|
| 697 | of alphabetic characters.
|
|---|
| 698 | Substrings matched by parenthesized subexpressions within the regular
|
|---|
| 699 | expression are saved in the array variable \fBBASH_REMATCH\fP.
|
|---|
| 700 | The element of \fBBASH_REMATCH\fP with index 0 is the portion of the string
|
|---|
| 701 | matching the entire regular expression.
|
|---|
| 702 | The element of \fBBASH_REMATCH\fP with index \fIn\fP is the portion of the
|
|---|
| 703 | string matching the \fIn\fPth parenthesized subexpression.
|
|---|
| 704 | .if t .sp 0.5
|
|---|
| 705 | .if n .sp 1
|
|---|
| 706 | Expressions may be combined using the following operators, listed
|
|---|
| 707 | in decreasing order of precedence:
|
|---|
| 708 | .if t .sp 0.5
|
|---|
| 709 | .if n .sp 1
|
|---|
| 710 | .RS
|
|---|
| 711 | .PD 0
|
|---|
| 712 | .TP
|
|---|
| 713 | .B ( \fIexpression\fP )
|
|---|
| 714 | Returns the value of \fIexpression\fP.
|
|---|
| 715 | This may be used to override the normal precedence of operators.
|
|---|
| 716 | .TP
|
|---|
| 717 | .B ! \fIexpression\fP
|
|---|
| 718 | True if
|
|---|
| 719 | .I expression
|
|---|
| 720 | is false.
|
|---|
| 721 | .TP
|
|---|
| 722 | \fIexpression1\fP \fB&&\fP \fIexpression2\fP
|
|---|
| 723 | True if both
|
|---|
| 724 | .I expression1
|
|---|
| 725 | and
|
|---|
| 726 | .I expression2
|
|---|
| 727 | are true.
|
|---|
| 728 | .TP
|
|---|
| 729 | .if t \fIexpression1\fP \fB\(bv\(bv\fP \fIexpression2\fP
|
|---|
| 730 | .if n \fIexpression1\fP \fB||\fP \fIexpression2\fP
|
|---|
| 731 | True if either
|
|---|
| 732 | .I expression1
|
|---|
| 733 | or
|
|---|
| 734 | .I expression2
|
|---|
| 735 | is true.
|
|---|
| 736 | .PD
|
|---|
| 737 | .LP
|
|---|
| 738 | The \fB&&\fP and
|
|---|
| 739 | .if t \fB\(bv\(bv\fP
|
|---|
| 740 | .if n \fB||\fP
|
|---|
| 741 | operators do not evaluate \fIexpression2\fP if the value of
|
|---|
| 742 | \fIexpression1\fP is sufficient to determine the return value of
|
|---|
| 743 | the entire conditional expression.
|
|---|
| 744 | .RE
|
|---|
| 745 | .TP
|
|---|
| 746 | \fBfor\fP \fIname\fP [ \fBin\fP \fIword\fP ] ; \fBdo\fP \fIlist\fP ; \fBdone\fP
|
|---|
| 747 | The list of words following \fBin\fP is expanded, generating a list
|
|---|
| 748 | of items.
|
|---|
| 749 | The variable \fIname\fP is set to each element of this list
|
|---|
| 750 | in turn, and \fIlist\fP is executed each time.
|
|---|
| 751 | If the \fBin\fP \fIword\fP is omitted, the \fBfor\fP command executes
|
|---|
| 752 | \fIlist\fP once for each positional parameter that is set (see
|
|---|
| 753 | .SM
|
|---|
| 754 | .B PARAMETERS
|
|---|
| 755 | below).
|
|---|
| 756 | The return status is the exit status of the last command that executes.
|
|---|
| 757 | If the expansion of the items following \fBin\fP results in an empty
|
|---|
| 758 | list, no commands are executed, and the return status is 0.
|
|---|
| 759 | .TP
|
|---|
| 760 | \fBfor\fP (( \fIexpr1\fP ; \fIexpr2\fP ; \fIexpr3\fP )) ; \fBdo\fP \fIlist\fP ; \fBdone\fP
|
|---|
| 761 | First, the arithmetic expression \fIexpr1\fP is evaluated according
|
|---|
| 762 | to the rules described below under
|
|---|
| 763 | .SM
|
|---|
| 764 | .BR "ARITHMETIC EVALUATION" .
|
|---|
| 765 | The arithmetic expression \fIexpr2\fP is then evaluated repeatedly
|
|---|
| 766 | until it evaluates to zero.
|
|---|
| 767 | Each time \fIexpr2\fP evaluates to a non-zero value, \fIlist\fP is
|
|---|
| 768 | executed and the arithmetic expression \fIexpr3\fP is evaluated.
|
|---|
| 769 | If any expression is omitted, it behaves as if it evaluates to 1.
|
|---|
| 770 | The return value is the exit status of the last command in \fIlist\fP
|
|---|
| 771 | that is executed, or false if any of the expressions is invalid.
|
|---|
| 772 | .TP
|
|---|
| 773 | \fBselect\fP \fIname\fP [ \fBin\fP \fIword\fP ] ; \fBdo\fP \fIlist\fP ; \fBdone\fP
|
|---|
| 774 | The list of words following \fBin\fP is expanded, generating a list
|
|---|
| 775 | of items. The set of expanded words is printed on the standard
|
|---|
| 776 | error, each preceded by a number. If the \fBin\fP
|
|---|
| 777 | \fIword\fP is omitted, the positional parameters are printed (see
|
|---|
| 778 | .SM
|
|---|
| 779 | .B PARAMETERS
|
|---|
| 780 | below). The
|
|---|
| 781 | .B PS3
|
|---|
| 782 | prompt is then displayed and a line read from the standard input.
|
|---|
| 783 | If the line consists of a number corresponding to one of
|
|---|
| 784 | the displayed words, then the value of
|
|---|
| 785 | .I name
|
|---|
| 786 | is set to that word. If the line is empty, the words and prompt
|
|---|
| 787 | are displayed again. If EOF is read, the command completes. Any
|
|---|
| 788 | other value read causes
|
|---|
| 789 | .I name
|
|---|
| 790 | to be set to null. The line read is saved in the variable
|
|---|
| 791 | .BR REPLY .
|
|---|
| 792 | The
|
|---|
| 793 | .I list
|
|---|
| 794 | is executed after each selection until a
|
|---|
| 795 | .B break
|
|---|
| 796 | command is executed.
|
|---|
| 797 | The exit status of
|
|---|
| 798 | .B select
|
|---|
| 799 | is the exit status of the last command executed in
|
|---|
| 800 | .IR list ,
|
|---|
| 801 | or zero if no commands were executed.
|
|---|
| 802 | .TP
|
|---|
| 803 | \fBcase\fP \fIword\fP \fBin\fP [ [(] \fIpattern\fP [ \fB|\fP \fIpattern\fP ] \
|
|---|
| 804 | ... ) \fIlist\fP ;; ] ... \fBesac\fP
|
|---|
| 805 | A \fBcase\fP command first expands \fIword\fP, and tries to match
|
|---|
| 806 | it against each \fIpattern\fP in turn, using the same matching rules
|
|---|
| 807 | as for pathname expansion (see
|
|---|
| 808 | .B Pathname Expansion
|
|---|
| 809 | below).
|
|---|
| 810 | If the shell option
|
|---|
| 811 | .B nocasematch
|
|---|
| 812 | is enabled, the match is performed without regard to the case
|
|---|
| 813 | of alphabetic characters.
|
|---|
| 814 | When a match is found, the
|
|---|
| 815 | corresponding \fIlist\fP is executed. After the first match, no
|
|---|
| 816 | subsequent matches are attempted. The exit status is zero if no
|
|---|
| 817 | pattern matches. Otherwise, it is the exit status of the
|
|---|
| 818 | last command executed in \fIlist\fP.
|
|---|
| 819 | .TP
|
|---|
| 820 | \fBif\fP \fIlist\fP; \fBthen\fP \fIlist;\fP \
|
|---|
| 821 | [ \fBelif\fP \fIlist\fP; \fBthen\fP \fIlist\fP; ] ... \
|
|---|
| 822 | [ \fBelse\fP \fIlist\fP; ] \fBfi\fP
|
|---|
| 823 | The
|
|---|
| 824 | .B if
|
|---|
| 825 | .I list
|
|---|
| 826 | is executed. If its exit status is zero, the
|
|---|
| 827 | \fBthen\fP \fIlist\fP is executed. Otherwise, each \fBelif\fP
|
|---|
| 828 | \fIlist\fP is executed in turn, and if its exit status is zero,
|
|---|
| 829 | the corresponding \fBthen\fP \fIlist\fP is executed and the
|
|---|
| 830 | command completes. Otherwise, the \fBelse\fP \fIlist\fP is
|
|---|
| 831 | executed, if present. The exit status is the exit status of the
|
|---|
| 832 | last command executed, or zero if no condition tested true.
|
|---|
| 833 | .TP
|
|---|
| 834 | \fBwhile\fP \fIlist\fP; \fBdo\fP \fIlist\fP; \fBdone\fP
|
|---|
| 835 | .PD 0
|
|---|
| 836 | .TP
|
|---|
| 837 | \fBuntil\fP \fIlist\fP; \fBdo\fP \fIlist\fP; \fBdone\fP
|
|---|
| 838 | .PD
|
|---|
| 839 | The \fBwhile\fP command continuously executes the \fBdo\fP
|
|---|
| 840 | \fIlist\fP as long as the last command in \fIlist\fP returns
|
|---|
| 841 | an exit status of zero. The \fBuntil\fP command is identical
|
|---|
| 842 | to the \fBwhile\fP command, except that the test is negated;
|
|---|
| 843 | the
|
|---|
| 844 | .B do
|
|---|
| 845 | .I list
|
|---|
| 846 | is executed as long as the last command in
|
|---|
| 847 | .I list
|
|---|
| 848 | returns a non-zero exit status.
|
|---|
| 849 | The exit status of the \fBwhile\fP and \fBuntil\fP commands
|
|---|
| 850 | is the exit status
|
|---|
| 851 | of the last \fBdo\fP \fIlist\fP command executed, or zero if
|
|---|
| 852 | none was executed.
|
|---|
| 853 | .SS Shell Function Definitions
|
|---|
| 854 | .PP
|
|---|
| 855 | A shell function is an object that is called like a simple command and
|
|---|
| 856 | executes a compound command with a new set of positional parameters.
|
|---|
| 857 | Shell functions are declared as follows:
|
|---|
| 858 | .TP
|
|---|
| 859 | [ \fBfunction\fP ] \fIname\fP () \fIcompound\-command\fP [\fIredirection\fP]
|
|---|
| 860 | This defines a function named \fIname\fP.
|
|---|
| 861 | The reserved word \fBfunction\fP is optional.
|
|---|
| 862 | If the \fBfunction\fP reserved word is supplied, the parentheses are optional.
|
|---|
| 863 | The \fIbody\fP of the function is the compound command
|
|---|
| 864 | .I compound\-command
|
|---|
| 865 | (see \fBCompound Commands\fP above).
|
|---|
| 866 | That command is usually a \fIlist\fP of commands between { and }, but
|
|---|
| 867 | may be any command listed under \fBCompound Commands\fP above.
|
|---|
| 868 | \fIcompound\-command\fP is executed whenever \fIname\fP is specified as the
|
|---|
| 869 | name of a simple command.
|
|---|
| 870 | Any redirections (see
|
|---|
| 871 | .SM
|
|---|
| 872 | .B REDIRECTION
|
|---|
| 873 | below) specified when a function is defined are performed
|
|---|
| 874 | when the function is executed.
|
|---|
| 875 | The exit status of a function definition is zero unless a syntax error
|
|---|
| 876 | occurs or a readonly function with the same name already exists.
|
|---|
| 877 | When executed, the exit status of a function is the exit status of the
|
|---|
| 878 | last command executed in the body. (See
|
|---|
| 879 | .SM
|
|---|
| 880 | .B FUNCTIONS
|
|---|
| 881 | below.)
|
|---|
| 882 | .SH COMMENTS
|
|---|
| 883 | In a non-interactive shell, or an interactive shell in which the
|
|---|
| 884 | .B interactive_comments
|
|---|
| 885 | option to the
|
|---|
| 886 | .B shopt
|
|---|
| 887 | builtin is enabled (see
|
|---|
| 888 | .SM
|
|---|
| 889 | .B "SHELL BUILTIN COMMANDS"
|
|---|
| 890 | below), a word beginning with
|
|---|
| 891 | .B #
|
|---|
| 892 | causes that word and all remaining characters on that line to
|
|---|
| 893 | be ignored. An interactive shell without the
|
|---|
| 894 | .B interactive_comments
|
|---|
| 895 | option enabled does not allow comments. The
|
|---|
| 896 | .B interactive_comments
|
|---|
| 897 | option is on by default in interactive shells.
|
|---|
| 898 | .SH QUOTING
|
|---|
| 899 | \fIQuoting\fP is used to remove the special meaning of certain
|
|---|
| 900 | characters or words to the shell. Quoting can be used to
|
|---|
| 901 | disable special treatment for special characters, to prevent
|
|---|
| 902 | reserved words from being recognized as such, and to prevent
|
|---|
| 903 | parameter expansion.
|
|---|
| 904 | .PP
|
|---|
| 905 | Each of the \fImetacharacters\fP listed above under
|
|---|
| 906 | .SM
|
|---|
| 907 | .B DEFINITIONS
|
|---|
| 908 | has special meaning to the shell and must be quoted if it is to
|
|---|
| 909 | represent itself.
|
|---|
| 910 | .PP
|
|---|
| 911 | When the command history expansion facilities are being used
|
|---|
| 912 | (see
|
|---|
| 913 | .SM
|
|---|
| 914 | .B HISTORY EXPANSION
|
|---|
| 915 | below), the
|
|---|
| 916 | \fIhistory expansion\fP character, usually \fB!\fP, must be quoted
|
|---|
| 917 | to prevent history expansion.
|
|---|
| 918 | .PP
|
|---|
| 919 | There are three quoting mechanisms: the
|
|---|
| 920 | .IR "escape character" ,
|
|---|
| 921 | single quotes, and double quotes.
|
|---|
| 922 | .PP
|
|---|
| 923 | A non-quoted backslash (\fB\e\fP) is the
|
|---|
| 924 | .IR "escape character" .
|
|---|
| 925 | It preserves the literal value of the next character that follows,
|
|---|
| 926 | with the exception of <newline>. If a \fB\e\fP<newline> pair
|
|---|
| 927 | appears, and the backslash is not itself quoted, the \fB\e\fP<newline>
|
|---|
| 928 | is treated as a line continuation (that is, it is removed from the
|
|---|
| 929 | input stream and effectively ignored).
|
|---|
| 930 | .PP
|
|---|
| 931 | Enclosing characters in single quotes preserves the literal value
|
|---|
| 932 | of each character within the quotes. A single quote may not occur
|
|---|
| 933 | between single quotes, even when preceded by a backslash.
|
|---|
| 934 | .PP
|
|---|
| 935 | Enclosing characters in double quotes preserves the literal value
|
|---|
| 936 | of all characters within the quotes, with the exception of
|
|---|
| 937 | .BR $ ,
|
|---|
| 938 | .BR ` ,
|
|---|
| 939 | .BR \e ,
|
|---|
| 940 | and, when history expansion is enabled,
|
|---|
| 941 | .BR ! .
|
|---|
| 942 | The characters
|
|---|
| 943 | .B $
|
|---|
| 944 | and
|
|---|
| 945 | .B `
|
|---|
| 946 | retain their special meaning within double quotes. The backslash
|
|---|
| 947 | retains its special meaning only when followed by one of the following
|
|---|
| 948 | characters:
|
|---|
| 949 | .BR $ ,
|
|---|
| 950 | .BR ` ,
|
|---|
| 951 | \^\fB"\fP\^,
|
|---|
| 952 | .BR \e ,
|
|---|
| 953 | or
|
|---|
| 954 | .BR <newline> .
|
|---|
| 955 | A double quote may be quoted within double quotes by preceding it with
|
|---|
| 956 | a backslash.
|
|---|
| 957 | If enabled, history expansion will be performed unless an
|
|---|
| 958 | .B !
|
|---|
| 959 | appearing in double quotes is escaped using a backslash.
|
|---|
| 960 | The backslash preceding the
|
|---|
| 961 | .B !
|
|---|
| 962 | is not removed.
|
|---|
| 963 | .PP
|
|---|
| 964 | The special parameters
|
|---|
| 965 | .B *
|
|---|
| 966 | and
|
|---|
| 967 | .B @
|
|---|
| 968 | have special meaning when in double
|
|---|
| 969 | quotes (see
|
|---|
| 970 | .SM
|
|---|
| 971 | .B PARAMETERS
|
|---|
| 972 | below).
|
|---|
| 973 | .PP
|
|---|
| 974 | Words of the form \fB$\fP'\fIstring\fP' are treated specially. The
|
|---|
| 975 | word expands to \fIstring\fP, with backslash-escaped characters replaced
|
|---|
| 976 | as specified by the ANSI C standard. Backslash escape sequences, if
|
|---|
| 977 | present, are decoded as follows:
|
|---|
| 978 | .RS
|
|---|
| 979 | .PD 0
|
|---|
| 980 | .TP
|
|---|
| 981 | .B \ea
|
|---|
| 982 | alert (bell)
|
|---|
| 983 | .TP
|
|---|
| 984 | .B \eb
|
|---|
| 985 | backspace
|
|---|
| 986 | .TP
|
|---|
| 987 | .B \ee
|
|---|
| 988 | an escape character
|
|---|
| 989 | .TP
|
|---|
| 990 | .B \ef
|
|---|
| 991 | form feed
|
|---|
| 992 | .TP
|
|---|
| 993 | .B \en
|
|---|
| 994 | new line
|
|---|
| 995 | .TP
|
|---|
| 996 | .B \er
|
|---|
| 997 | carriage return
|
|---|
| 998 | .TP
|
|---|
| 999 | .B \et
|
|---|
| 1000 | horizontal tab
|
|---|
| 1001 | .TP
|
|---|
| 1002 | .B \ev
|
|---|
| 1003 | vertical tab
|
|---|
| 1004 | .TP
|
|---|
| 1005 | .B \e\e
|
|---|
| 1006 | backslash
|
|---|
| 1007 | .TP
|
|---|
| 1008 | .B \e'
|
|---|
| 1009 | single quote
|
|---|
| 1010 | .TP
|
|---|
| 1011 | .B \e\fInnn\fP
|
|---|
| 1012 | the eight-bit character whose value is the octal value \fInnn\fP
|
|---|
| 1013 | (one to three digits)
|
|---|
| 1014 | .TP
|
|---|
| 1015 | .B \ex\fIHH\fP
|
|---|
| 1016 | the eight-bit character whose value is the hexadecimal value \fIHH\fP
|
|---|
| 1017 | (one or two hex digits)
|
|---|
| 1018 | .TP
|
|---|
| 1019 | .B \ec\fIx\fP
|
|---|
| 1020 | a control-\fIx\fP character
|
|---|
| 1021 | .PD
|
|---|
| 1022 | .RE
|
|---|
| 1023 | .LP
|
|---|
| 1024 | The expanded result is single-quoted, as if the dollar sign had
|
|---|
| 1025 | not been present.
|
|---|
| 1026 | .PP
|
|---|
| 1027 | A double-quoted string preceded by a dollar sign (\fB$\fP) will cause
|
|---|
| 1028 | the string to be translated according to the current locale.
|
|---|
| 1029 | If the current locale is \fBC\fP or \fBPOSIX\fP, the dollar sign
|
|---|
| 1030 | is ignored.
|
|---|
| 1031 | If the string is translated and replaced, the replacement is
|
|---|
| 1032 | double-quoted.
|
|---|
| 1033 | .SH PARAMETERS
|
|---|
| 1034 | A
|
|---|
| 1035 | .I parameter
|
|---|
| 1036 | is an entity that stores values.
|
|---|
| 1037 | It can be a
|
|---|
| 1038 | .IR name ,
|
|---|
| 1039 | a number, or one of the special characters listed below under
|
|---|
| 1040 | .BR "Special Parameters" .
|
|---|
| 1041 | A
|
|---|
| 1042 | .I variable
|
|---|
| 1043 | is a parameter denoted by a
|
|---|
| 1044 | .IR name .
|
|---|
| 1045 | A variable has a \fIvalue\fP and zero or more \fIattributes\fP.
|
|---|
| 1046 | Attributes are assigned using the
|
|---|
| 1047 | .B declare
|
|---|
| 1048 | builtin command (see
|
|---|
| 1049 | .B declare
|
|---|
| 1050 | below in
|
|---|
| 1051 | .SM
|
|---|
| 1052 | .BR "SHELL BUILTIN COMMANDS" ).
|
|---|
| 1053 | .PP
|
|---|
| 1054 | A parameter is set if it has been assigned a value. The null string is
|
|---|
| 1055 | a valid value. Once a variable is set, it may be unset only by using
|
|---|
| 1056 | the
|
|---|
| 1057 | .B unset
|
|---|
| 1058 | builtin command (see
|
|---|
| 1059 | .SM
|
|---|
| 1060 | .B SHELL BUILTIN COMMANDS
|
|---|
| 1061 | below).
|
|---|
| 1062 | .PP
|
|---|
| 1063 | A
|
|---|
| 1064 | .I variable
|
|---|
| 1065 | may be assigned to by a statement of the form
|
|---|
| 1066 | .RS
|
|---|
| 1067 | .PP
|
|---|
| 1068 | \fIname\fP=[\fIvalue\fP]
|
|---|
| 1069 | .RE
|
|---|
| 1070 | .PP
|
|---|
| 1071 | If
|
|---|
| 1072 | .I value
|
|---|
| 1073 | is not given, the variable is assigned the null string. All
|
|---|
| 1074 | .I values
|
|---|
| 1075 | undergo tilde expansion, parameter and variable expansion,
|
|---|
| 1076 | command substitution, arithmetic expansion, and quote
|
|---|
| 1077 | removal (see
|
|---|
| 1078 | .SM
|
|---|
| 1079 | .B EXPANSION
|
|---|
| 1080 | below). If the variable has its
|
|---|
| 1081 | .B integer
|
|---|
| 1082 | attribute set, then
|
|---|
| 1083 | .I value
|
|---|
| 1084 | is evaluated as an arithmetic expression even if the $((...)) expansion is
|
|---|
| 1085 | not used (see
|
|---|
| 1086 | .B "Arithmetic Expansion"
|
|---|
| 1087 | below).
|
|---|
| 1088 | Word splitting is not performed, with the exception
|
|---|
| 1089 | of \fB"$@"\fP as explained below under
|
|---|
| 1090 | .BR "Special Parameters" .
|
|---|
| 1091 | Pathname expansion is not performed.
|
|---|
| 1092 | Assignment statements may also appear as arguments to the
|
|---|
| 1093 | .BR alias ,
|
|---|
| 1094 | .BR declare ,
|
|---|
| 1095 | .BR typeset ,
|
|---|
| 1096 | .BR export ,
|
|---|
| 1097 | .BR readonly ,
|
|---|
| 1098 | and
|
|---|
| 1099 | .B local
|
|---|
| 1100 | builtin commands.
|
|---|
| 1101 | .PP
|
|---|
| 1102 | In the context where an assignment statement is assigning a value
|
|---|
| 1103 | to a shell variable or array index, the += operator can be used to
|
|---|
| 1104 | append to or add to the variable's previous value.
|
|---|
| 1105 | When += is applied to a variable for which the integer attribute has been
|
|---|
| 1106 | set, \fIvalue\fP is evaluated as an arithmetic expression and added to the
|
|---|
| 1107 | variable's current value, which is also evaluated.
|
|---|
| 1108 | When += is applied to an array variable using compound assignment (see
|
|---|
| 1109 | .B Arrays
|
|---|
| 1110 | below), the
|
|---|
| 1111 | variable's value is not unset (as it is when using =), and new values are
|
|---|
| 1112 | appended to the array beginning at one greater than the array's maximum index.
|
|---|
| 1113 | When applied to a string-valued variable, \fIvalue\fP is expanded and
|
|---|
| 1114 | appended to the variable's value.
|
|---|
| 1115 | .SS Positional Parameters
|
|---|
| 1116 | .PP
|
|---|
| 1117 | A
|
|---|
| 1118 | .I positional parameter
|
|---|
| 1119 | is a parameter denoted by one or more
|
|---|
| 1120 | digits, other than the single digit 0. Positional parameters are
|
|---|
| 1121 | assigned from the shell's arguments when it is invoked,
|
|---|
| 1122 | and may be reassigned using the
|
|---|
| 1123 | .B set
|
|---|
| 1124 | builtin command. Positional parameters may not be assigned to
|
|---|
| 1125 | with assignment statements. The positional parameters are
|
|---|
| 1126 | temporarily replaced when a shell function is executed (see
|
|---|
| 1127 | .SM
|
|---|
| 1128 | .B FUNCTIONS
|
|---|
| 1129 | below).
|
|---|
| 1130 | .PP
|
|---|
| 1131 | When a positional parameter consisting of more than a single
|
|---|
| 1132 | digit is expanded, it must be enclosed in braces (see
|
|---|
| 1133 | .SM
|
|---|
| 1134 | .B EXPANSION
|
|---|
| 1135 | below).
|
|---|
| 1136 | .SS Special Parameters
|
|---|
| 1137 | .PP
|
|---|
| 1138 | The shell treats several parameters specially. These parameters may
|
|---|
| 1139 | only be referenced; assignment to them is not allowed.
|
|---|
| 1140 | .PD 0
|
|---|
| 1141 | .TP
|
|---|
| 1142 | .B *
|
|---|
| 1143 | Expands to the positional parameters, starting from one. When the
|
|---|
| 1144 | expansion occurs within double quotes, it expands to a single word
|
|---|
| 1145 | with the value of each parameter separated by the first character
|
|---|
| 1146 | of the
|
|---|
| 1147 | .SM
|
|---|
| 1148 | .B IFS
|
|---|
| 1149 | special variable. That is, "\fB$*\fP" is equivalent
|
|---|
| 1150 | to "\fB$1\fP\fIc\fP\fB$2\fP\fIc\fP\fB...\fP", where
|
|---|
| 1151 | .I c
|
|---|
| 1152 | is the first character of the value of the
|
|---|
| 1153 | .SM
|
|---|
| 1154 | .B IFS
|
|---|
| 1155 | variable. If
|
|---|
| 1156 | .SM
|
|---|
| 1157 | .B IFS
|
|---|
| 1158 | is unset, the parameters are separated by spaces.
|
|---|
| 1159 | If
|
|---|
| 1160 | .SM
|
|---|
| 1161 | .B IFS
|
|---|
| 1162 | is null, the parameters are joined without intervening separators.
|
|---|
| 1163 | .TP
|
|---|
| 1164 | .B @
|
|---|
| 1165 | Expands to the positional parameters, starting from one. When the
|
|---|
| 1166 | expansion occurs within double quotes, each parameter expands to a
|
|---|
| 1167 | separate word. That is, "\fB$@\fP" is equivalent to
|
|---|
| 1168 | "\fB$1\fP" "\fB$2\fP" ...
|
|---|
| 1169 | If the double-quoted expansion occurs within a word, the expansion of
|
|---|
| 1170 | the first parameter is joined with the beginning part of the original
|
|---|
| 1171 | word, and the expansion of the last parameter is joined with the last
|
|---|
| 1172 | part of the original word.
|
|---|
| 1173 | When there are no positional parameters, "\fB$@\fP" and
|
|---|
| 1174 | .B $@
|
|---|
| 1175 | expand to nothing (i.e., they are removed).
|
|---|
| 1176 | .TP
|
|---|
| 1177 | .B #
|
|---|
| 1178 | Expands to the number of positional parameters in decimal.
|
|---|
| 1179 | .TP
|
|---|
| 1180 | .B ?
|
|---|
| 1181 | Expands to the status of the most recently executed foreground
|
|---|
| 1182 | pipeline.
|
|---|
| 1183 | .TP
|
|---|
| 1184 | .B \-
|
|---|
| 1185 | Expands to the current option flags as specified upon invocation,
|
|---|
| 1186 | by the
|
|---|
| 1187 | .B set
|
|---|
| 1188 | builtin command, or those set by the shell itself
|
|---|
| 1189 | (such as the
|
|---|
| 1190 | .B \-i
|
|---|
| 1191 | option).
|
|---|
| 1192 | .TP
|
|---|
| 1193 | .B $
|
|---|
| 1194 | Expands to the process ID of the shell. In a () subshell, it
|
|---|
| 1195 | expands to the process ID of the current shell, not the
|
|---|
| 1196 | subshell.
|
|---|
| 1197 | .TP
|
|---|
| 1198 | .B !
|
|---|
| 1199 | Expands to the process ID of the most recently executed background
|
|---|
| 1200 | (asynchronous) command.
|
|---|
| 1201 | .TP
|
|---|
| 1202 | .B 0
|
|---|
| 1203 | Expands to the name of the shell or shell script. This is set at
|
|---|
| 1204 | shell initialization. If
|
|---|
| 1205 | .B bash
|
|---|
| 1206 | is invoked with a file of commands,
|
|---|
| 1207 | .B $0
|
|---|
| 1208 | is set to the name of that file. If
|
|---|
| 1209 | .B bash
|
|---|
| 1210 | is started with the
|
|---|
| 1211 | .B \-c
|
|---|
| 1212 | option, then
|
|---|
| 1213 | .B $0
|
|---|
| 1214 | is set to the first argument after the string to be
|
|---|
| 1215 | executed, if one is present. Otherwise, it is set
|
|---|
| 1216 | to the file name used to invoke
|
|---|
| 1217 | .BR bash ,
|
|---|
| 1218 | as given by argument zero.
|
|---|
| 1219 | .TP
|
|---|
| 1220 | .B _
|
|---|
| 1221 | At shell startup, set to the absolute pathname used to invoke the
|
|---|
| 1222 | shell or shell script being executed as passed in the environment
|
|---|
| 1223 | or argument list.
|
|---|
| 1224 | Subsequently, expands to the last argument to the previous command,
|
|---|
| 1225 | after expansion.
|
|---|
| 1226 | Also set to the full pathname used to invoke each command executed
|
|---|
| 1227 | and placed in the environment exported to that command.
|
|---|
| 1228 | When checking mail, this parameter holds the name of the mail file
|
|---|
| 1229 | currently being checked.
|
|---|
| 1230 | .PD
|
|---|
| 1231 | .SS Shell Variables
|
|---|
| 1232 | .PP
|
|---|
| 1233 | The following variables are set by the shell:
|
|---|
| 1234 | .PP
|
|---|
| 1235 | .PD 0
|
|---|
| 1236 | .TP
|
|---|
| 1237 | .B BASH
|
|---|
| 1238 | Expands to the full file name used to invoke this instance of
|
|---|
| 1239 | .BR bash .
|
|---|
| 1240 | .TP
|
|---|
| 1241 | .B BASH_ARGC
|
|---|
| 1242 | An array variable whose values are the number of parameters in each
|
|---|
| 1243 | frame of the current bash execution call stack.
|
|---|
| 1244 | The number of
|
|---|
| 1245 | parameters to the current subroutine (shell function or script executed
|
|---|
| 1246 | with \fB.\fP or \fBsource\fP) is at the top of the stack.
|
|---|
| 1247 | When a subroutine is executed, the number of parameters passed is pushed onto
|
|---|
| 1248 | \fBBASH_ARGC\fP.
|
|---|
| 1249 | The shell sets \fBBASH_ARGC\fP only when in extended debugging mode
|
|---|
| 1250 | (see the description of the
|
|---|
| 1251 | .B extdebug
|
|---|
| 1252 | option to the
|
|---|
| 1253 | .B shopt
|
|---|
| 1254 | builtin below)
|
|---|
| 1255 | .TP
|
|---|
| 1256 | .B BASH_ARGV
|
|---|
| 1257 | An array variable containing all of the parameters in the current bash
|
|---|
| 1258 | execution call stack. The final parameter of the last subroutine call
|
|---|
| 1259 | is at the top of the stack; the first parameter of the initial call is
|
|---|
| 1260 | at the bottom. When a subroutine is executed, the parameters supplied
|
|---|
| 1261 | are pushed onto \fBBASH_ARGV\fP.
|
|---|
| 1262 | The shell sets \fBBASH_ARGV\fP only when in extended debugging mode
|
|---|
| 1263 | (see the description of the
|
|---|
| 1264 | .B extdebug
|
|---|
| 1265 | option to the
|
|---|
| 1266 | .B shopt
|
|---|
| 1267 | builtin below)
|
|---|
| 1268 | .TP
|
|---|
| 1269 | .B BASH_COMMAND
|
|---|
| 1270 | The command currently being executed or about to be executed, unless the
|
|---|
| 1271 | shell is executing a command as the result of a trap,
|
|---|
| 1272 | in which case it is the command executing at the time of the trap.
|
|---|
| 1273 | .TP
|
|---|
| 1274 | .B BASH_EXECUTION_STRING
|
|---|
| 1275 | The command argument to the \fB\-c\fP invocation option.
|
|---|
| 1276 | .TP
|
|---|
| 1277 | .B BASH_LINENO
|
|---|
| 1278 | An array variable whose members are the line numbers in source files
|
|---|
| 1279 | corresponding to each member of \fBFUNCNAME\fP.
|
|---|
| 1280 | \fB${BASH_LINENO[\fP\fI$i\fP\fB]}\fP is the line number in the source
|
|---|
| 1281 | file where \fB${FUNCNAME[\fP\fI$ifP\fB]}\fP was called.
|
|---|
| 1282 | The corresponding source file name is \fB${BASH_SOURCE[\fP\fI$i\fP\fB]}\fB.
|
|---|
| 1283 | Use \fBLINENO\fP to obtain the current line number.
|
|---|
| 1284 | .TP
|
|---|
| 1285 | .B BASH_REMATCH
|
|---|
| 1286 | An array variable whose members are assigned by the \fB=~\fP binary
|
|---|
| 1287 | operator to the \fB[[\fP conditional command.
|
|---|
| 1288 | The element with index 0 is the portion of the string
|
|---|
| 1289 | matching the entire regular expression.
|
|---|
| 1290 | The element with index \fIn\fP is the portion of the
|
|---|
| 1291 | string matching the \fIn\fPth parenthesized subexpression.
|
|---|
| 1292 | This variable is read-only.
|
|---|
| 1293 | .TP
|
|---|
| 1294 | .B BASH_SOURCE
|
|---|
| 1295 | An array variable whose members are the source filenames corresponding
|
|---|
| 1296 | to the elements in the \fBFUNCNAME\fP array variable.
|
|---|
| 1297 | .TP
|
|---|
| 1298 | .B BASH_SUBSHELL
|
|---|
| 1299 | Incremented by one each time a subshell or subshell environment is spawned.
|
|---|
| 1300 | The initial value is 0.
|
|---|
| 1301 | .TP
|
|---|
| 1302 | .B BASH_VERSINFO
|
|---|
| 1303 | A readonly array variable whose members hold version information for
|
|---|
| 1304 | this instance of
|
|---|
| 1305 | .BR bash .
|
|---|
| 1306 | The values assigned to the array members are as follows:
|
|---|
| 1307 | .sp .5
|
|---|
| 1308 | .RS
|
|---|
| 1309 | .PD 0
|
|---|
| 1310 | .TP 24
|
|---|
| 1311 | .B BASH_VERSINFO[\fR0\fP]
|
|---|
| 1312 | The major version number (the \fIrelease\fP).
|
|---|
| 1313 | .TP
|
|---|
| 1314 | .B BASH_VERSINFO[\fR1\fP]
|
|---|
| 1315 | The minor version number (the \fIversion\fP).
|
|---|
| 1316 | .TP
|
|---|
| 1317 | .B BASH_VERSINFO[\fR2\fP]
|
|---|
| 1318 | The patch level.
|
|---|
| 1319 | .TP
|
|---|
| 1320 | .B BASH_VERSINFO[\fR3\fP]
|
|---|
| 1321 | The build version.
|
|---|
| 1322 | .TP
|
|---|
| 1323 | .B BASH_VERSINFO[\fR4\fP]
|
|---|
| 1324 | The release status (e.g., \fIbeta1\fP).
|
|---|
| 1325 | .TP
|
|---|
| 1326 | .B BASH_VERSINFO[\fR5\fP]
|
|---|
| 1327 | The value of \fBMACHTYPE\fP.
|
|---|
| 1328 | .PD
|
|---|
| 1329 | .RE
|
|---|
| 1330 | .TP
|
|---|
| 1331 | .B BASH_VERSION
|
|---|
| 1332 | Expands to a string describing the version of this instance of
|
|---|
| 1333 | .BR bash .
|
|---|
| 1334 | .TP
|
|---|
| 1335 | .B COMP_CWORD
|
|---|
| 1336 | An index into \fB${COMP_WORDS}\fP of the word containing the current
|
|---|
| 1337 | cursor position.
|
|---|
| 1338 | This variable is available only in shell functions invoked by the
|
|---|
| 1339 | programmable completion facilities (see \fBProgrammable Completion\fP
|
|---|
| 1340 | below).
|
|---|
| 1341 | .TP
|
|---|
| 1342 | .B COMP_LINE
|
|---|
| 1343 | The current command line.
|
|---|
| 1344 | This variable is available only in shell functions and external
|
|---|
| 1345 | commands invoked by the
|
|---|
| 1346 | programmable completion facilities (see \fBProgrammable Completion\fP
|
|---|
| 1347 | below).
|
|---|
| 1348 | .TP
|
|---|
| 1349 | .B COMP_POINT
|
|---|
| 1350 | The index of the current cursor position relative to the beginning of
|
|---|
| 1351 | the current command.
|
|---|
| 1352 | If the current cursor position is at the end of the current command,
|
|---|
| 1353 | the value of this variable is equal to \fB${#COMP_LINE}\fP.
|
|---|
| 1354 | This variable is available only in shell functions and external
|
|---|
| 1355 | commands invoked by the
|
|---|
| 1356 | programmable completion facilities (see \fBProgrammable Completion\fP
|
|---|
| 1357 | below).
|
|---|
| 1358 | .TP
|
|---|
| 1359 | .B COMP_WORDBREAKS
|
|---|
| 1360 | The set of characters that the Readline library treats as word
|
|---|
| 1361 | separators when performing word completion.
|
|---|
| 1362 | If
|
|---|
| 1363 | .SM
|
|---|
| 1364 | .B COMP_WORDBREAKS
|
|---|
| 1365 | is unset, it loses its special properties, even if it is
|
|---|
| 1366 | subsequently reset.
|
|---|
| 1367 | .TP
|
|---|
| 1368 | .B COMP_WORDS
|
|---|
| 1369 | An array variable (see \fBArrays\fP below) consisting of the individual
|
|---|
| 1370 | words in the current command line.
|
|---|
| 1371 | This variable is available only in shell functions invoked by the
|
|---|
| 1372 | programmable completion facilities (see \fBProgrammable Completion\fP
|
|---|
| 1373 | below).
|
|---|
| 1374 | .TP
|
|---|
| 1375 | .B DIRSTACK
|
|---|
| 1376 | An array variable (see
|
|---|
| 1377 | .B Arrays
|
|---|
| 1378 | below) containing the current contents of the directory stack.
|
|---|
| 1379 | Directories appear in the stack in the order they are displayed by the
|
|---|
| 1380 | .B dirs
|
|---|
| 1381 | builtin.
|
|---|
| 1382 | Assigning to members of this array variable may be used to modify
|
|---|
| 1383 | directories already in the stack, but the
|
|---|
| 1384 | .B pushd
|
|---|
| 1385 | and
|
|---|
| 1386 | .B popd
|
|---|
| 1387 | builtins must be used to add and remove directories.
|
|---|
| 1388 | Assignment to this variable will not change the current directory.
|
|---|
| 1389 | If
|
|---|
| 1390 | .SM
|
|---|
| 1391 | .B DIRSTACK
|
|---|
| 1392 | is unset, it loses its special properties, even if it is
|
|---|
| 1393 | subsequently reset.
|
|---|
| 1394 | .TP
|
|---|
| 1395 | .B EUID
|
|---|
| 1396 | Expands to the effective user ID of the current user, initialized at
|
|---|
| 1397 | shell startup. This variable is readonly.
|
|---|
| 1398 | .TP
|
|---|
| 1399 | .B FUNCNAME
|
|---|
| 1400 | An array variable containing the names of all shell functions
|
|---|
| 1401 | currently in the execution call stack.
|
|---|
| 1402 | The element with index 0 is the name of any currently-executing
|
|---|
| 1403 | shell function.
|
|---|
| 1404 | The bottom-most element is "main".
|
|---|
| 1405 | This variable exists only when a shell function is executing.
|
|---|
| 1406 | Assignments to
|
|---|
| 1407 | .SM
|
|---|
| 1408 | .B FUNCNAME
|
|---|
| 1409 | have no effect and return an error status.
|
|---|
| 1410 | If
|
|---|
| 1411 | .SM
|
|---|
| 1412 | .B FUNCNAME
|
|---|
| 1413 | is unset, it loses its special properties, even if it is
|
|---|
| 1414 | subsequently reset.
|
|---|
| 1415 | .TP
|
|---|
| 1416 | .B GROUPS
|
|---|
| 1417 | An array variable containing the list of groups of which the current
|
|---|
| 1418 | user is a member.
|
|---|
| 1419 | Assignments to
|
|---|
| 1420 | .SM
|
|---|
| 1421 | .B GROUPS
|
|---|
| 1422 | have no effect and return an error status.
|
|---|
| 1423 | If
|
|---|
| 1424 | .SM
|
|---|
| 1425 | .B GROUPS
|
|---|
| 1426 | is unset, it loses its special properties, even if it is
|
|---|
| 1427 | subsequently reset.
|
|---|
| 1428 | .TP
|
|---|
| 1429 | .B HISTCMD
|
|---|
| 1430 | The history number, or index in the history list, of the current
|
|---|
| 1431 | command.
|
|---|
| 1432 | If
|
|---|
| 1433 | .SM
|
|---|
| 1434 | .B HISTCMD
|
|---|
| 1435 | is unset, it loses its special properties, even if it is
|
|---|
| 1436 | subsequently reset.
|
|---|
| 1437 | .TP
|
|---|
| 1438 | .B HOSTNAME
|
|---|
| 1439 | Automatically set to the name of the current host.
|
|---|
| 1440 | .TP
|
|---|
| 1441 | .B HOSTTYPE
|
|---|
| 1442 | Automatically set to a string that uniquely
|
|---|
| 1443 | describes the type of machine on which
|
|---|
| 1444 | .B bash
|
|---|
| 1445 | is executing.
|
|---|
| 1446 | The default is system-dependent.
|
|---|
| 1447 | .TP
|
|---|
| 1448 | .B LINENO
|
|---|
| 1449 | Each time this parameter is referenced, the shell substitutes
|
|---|
| 1450 | a decimal number representing the current sequential line number
|
|---|
| 1451 | (starting with 1) within a script or function. When not in a
|
|---|
| 1452 | script or function, the value substituted is not guaranteed to
|
|---|
| 1453 | be meaningful.
|
|---|
| 1454 | If
|
|---|
| 1455 | .SM
|
|---|
| 1456 | .B LINENO
|
|---|
| 1457 | is unset, it loses its special properties, even if it is
|
|---|
| 1458 | subsequently reset.
|
|---|
| 1459 | .TP
|
|---|
| 1460 | .B MACHTYPE
|
|---|
| 1461 | Automatically set to a string that fully describes the system
|
|---|
| 1462 | type on which
|
|---|
| 1463 | .B bash
|
|---|
| 1464 | is executing, in the standard GNU \fIcpu-company-system\fP format.
|
|---|
| 1465 | The default is system-dependent.
|
|---|
| 1466 | .TP
|
|---|
| 1467 | .B OLDPWD
|
|---|
| 1468 | The previous working directory as set by the
|
|---|
| 1469 | .B cd
|
|---|
| 1470 | command.
|
|---|
| 1471 | .TP
|
|---|
| 1472 | .B OPTARG
|
|---|
| 1473 | The value of the last option argument processed by the
|
|---|
| 1474 | .B getopts
|
|---|
| 1475 | builtin command (see
|
|---|
| 1476 | .SM
|
|---|
| 1477 | .B SHELL BUILTIN COMMANDS
|
|---|
| 1478 | below).
|
|---|
| 1479 | .TP
|
|---|
| 1480 | .B OPTIND
|
|---|
| 1481 | The index of the next argument to be processed by the
|
|---|
|
|---|