SEARCH
NEW RPMS
DIRECTORIES
ABOUT
FAQ
VARIOUS
BLOG
DONATE


YUM REPOSITORY

 
 

MAN page from OpenSuSE bash-doc-4.4-lp150.7.3.noarch.rpm

BASH

Section: User Commands (1)
Updated: 2016 August 26
Index 

NAME

bash - GNU Bourne-Again SHell 

SYNOPSIS

bash[options][command_string | file] 

COPYRIGHT

Bash is Copyright (C) 1989-2016 by the Free Software Foundation, Inc. 

DESCRIPTION

Bashis an sh-compatible command language interpreter thatexecutes commands read from the standard input or from a file.Bashalso incorporates useful features from the Korn and Cshells (ksh and csh).

Bashis intended to be a conformant implementation of theShell and Utilities portion of the IEEE POSIX specification(IEEE Standard 1003.1).Bashcan be configured to be POSIX-conformant by default. 

OPTIONS

All of the single-character shell options documented in thedescription of the set builtin command can be used as optionswhen the shell is invoked.In addition, bashinterprets the following options when it is invoked:

-c
If the-coption is present, then commands are read from the first non-option argumentcommand_string.If there are arguments after thecommand_string,the first argument is assigned to$0and any remaining arguments are assigned to the positional parameters.The assignment to$0sets the name of the shell, which is used in warning and error messages.
-i
If the-ioption is present, the shell isinteractive.
-l
Makebashact as if it had been invoked as a login shell (seeINVOCATIONbelow).
-r
If the-roption is present, the shell becomesrestricted(seeRESTRICTED SHELLbelow).
-s
If the-soption is present, or if no arguments remain after optionprocessing, then commands are read from the standard input.This option allows the positional parameters to be setwhen invoking an interactive shell.
-v
Print shell input lines as they are read.
-x
Print commands and their arguments as they are executed.
-D
A list of all double-quoted strings preceded by $is printed on the standard output.These are the strings thatare subject to language translation when the current localeis not C or POSIX.This implies the -n option; no commands will be executed.
[-+]O [shopt_option]
shopt_option is one of the shell options accepted by theshopt builtin (seeSHELL BUILTIN COMMANDSbelow).If shopt_option is present, -O sets the value of that option;+O unsets it.If shopt_option is not supplied, the names and values of the shelloptions accepted by shopt are printed on the standard output.If the invocation option is +O, the output is displayed in a formatthat may be reused as input.
--
A--signals the end of options and disables further option processing.Any arguments after the--are treated as filenames and arguments. An argument of-is equivalent to --.

Bashalso interprets a number of multi-character options.These options must appear on the command line before thesingle-character options to be recognized.

--debugger
Arrange for the debugger profile to be executed before the shellstarts.Turns on extended debugging mode (see the description of theextdebugoption to theshoptbuiltin below).
--dump-po-strings
Equivalent to -D, but the output is in the GNU gettextpo (portable object) file format.
--dump-strings
Equivalent to -D.
--help
Display a usage message on standard output and exit successfully.
--init-file file
--rcfile file
Execute commands fromfileinstead of the standard personal initialization file~/.bashrcif the shell is interactive (seeINVOCATIONbelow).
--login
Equivalent to -l.
--noediting
Do not use the GNUreadlinelibrary to read command lines when the shell is interactive.
--noprofile
Do not read either the system-wide startup file/etc/profileor any of the personal initialization files~/.bash_profile,~/.bash_login,or~/.profile.By default,bashreads these files when it is invoked as a login shell (seeINVOCATIONbelow).
--norc
Do not read and execute the personal initialization file~/.bashrcif the shell is interactive.This option is on by default if the shell is invoked assh.
--posix
Change the behavior of bash where the default operation differsfrom the POSIX standard to match the standard (posix mode).SeeSEE ALSObelow for a reference to a document that details how posix mode affectsbash's behavior.
--restricted
The shell becomes restricted (seeRESTRICTED SHELLbelow).
--verbose
Equivalent to -v.
--version
Show version information for this instance ofbashon the standard output and exit successfully.
 

ARGUMENTS

If arguments remain after option processing, and neither the-cnor the-soption has been supplied, the first argument is assumed tobe the name of a file containing shell commands.Ifbashis invoked in this fashion,$0is set to the name of the file, and the positional parametersare set to the remaining arguments.Bashreads and executes commands from this file, then exits.Bash's exit status is the exit status of the last commandexecuted in the script.If no commands are executed, the exit status is 0.An attempt is first made to open the file in the current directory, and,if no file is found, then the shell searches the directories inPATHfor the script. 

INVOCATION

A login shell is one whose first character of argument zero is a-,or one started with the--loginoption.

An interactive shell is one started without non-option arguments(unless -s is specified)and without the-coptionwhose standard input and error areboth connected to terminals (as determined byisatty(3)),or one started with the-ioption.PS1is set and$-includesiifbashis interactive,allowing a shell script or a startup file to test this state.

The following paragraphs describe howbashexecutes its startup files.If any of the files exist but cannot be read,bashreports an error.Tildes are expanded in filenames as described below underTilde Expansionin theEXPANSIONsection.

Whenbashis invoked as an interactive login shell, or as a non-interactive shellwith the --login option, it first reads andexecutes commands from the file /etc/profile, if thatfile exists.After reading that file, it looks for ~/.bash_profile,~/.bash_login, and ~/.profile, in that order, and readsand executes commands from the first one that exists and is readable.The--noprofileoption may be used when the shell is started to inhibit this behavior.Please note that the file /etc/profile includes an autodetection shellcode wether it has to source /etc/bash.bashrc as well as ~/.bashrc.

When an interactive login shell exits,or a non-interactive login shell executes the exit builtin command,bashreads and executes commands from the file ~/.bash_logout, if itexists.

When an interactive shell that is not a login shell is started,bashreads and executes commands from /etc/bash.bashrc then ~/.bashrcwhen those files exist and are readable. This may be inhibited by using the--norcoption.The --rcfile file option will forcebashto read and execute commands from file instead of ~/.bashrc.Please note that the file /etc/bash.bashrc includes an autodetection shellcode wether it is used for by a remote OpenSSH SSH client likessh(1)orslogin(1)to source the local /etc/profile if not already done.

Whenbashis started non-interactively, to run a shell script, for example, itlooks for the variableBASH_ENVin the environment, expands its value if it appears there, and uses theexpanded value as the name of a file to read and execute.Bashbehaves as if the following command were executed:

if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi

but the value of thePATHvariable is not used to search for the filename.

Ifbashis invoked with the namesh,it tries to mimic the startup behavior of historical versions ofshas closely as possible,while conforming to the POSIX standard as well.When invoked as an interactive login shell, or a non-interactiveshell with the --login option, it first attempts toread and execute commands from/etc/profileand~/.profile,in that order.The--noprofileoption may be used to inhibit this behavior.When invoked as an interactive shell with the namesh,bashlooks for the variableENV,expands its value if it is defined, and uses theexpanded value as the name of a file to read and execute.Since a shell invoked asshdoes not attempt to read and execute commands from any other startupfiles, the--rcfileoption has no effect.A non-interactive shell invoked with the nameshdoes not attempt to read any other startup files. When invoked assh,bashentersposixmode after the startup files are read.

Whenbashis started inposixmode, as with the--posixcommand line option, it follows the POSIX standard for startup files.In this mode, interactive shells expand theENVvariable and commands are read and executed from the filewhose name is the expanded value.No other startup files are read.

Bashattempts to determine when it is being run with its standard inputconnected to a network connection, as when executed by the remote shelldaemon, usually rshd, or the secure shell daemon sshd.Ifbashdetermines it is being run in this fashion, it reads and executescommands from /etc/bash.bashrc then ~/.bashrc whenthose files exist and are readable.It will not do this if invoked as sh.The--norcoption may be used to inhibit this behavior, and the--rcfileoption may be used to force another file to be read, but neitherrshd nor sshd generally invoke the shell with those optionsor allow them to be specified.

If the shell is started with the effective user (group) id not equal to thereal user (group) id, and the -p option is not supplied, no startupfiles are read, shell functions are not inherited from the environment, theSHELLOPTS,BASHOPTS,CDPATH,andGLOBIGNOREvariables, if they appear in the environment, are ignored,and the effective user id is set to the real user id.If the -p option is supplied at invocation, the startup behavior isthe same, but the effective user id is not reset. 

DEFINITIONS

The following definitions are used throughout the rest of thisdocument.

blank
A space or tab.
word
A sequence of characters considered as a single unit by the shell.Also known as atoken.
name
Awordconsisting only of alphanumeric characters and underscores, andbeginning with an alphabetic character or an underscore. Alsoreferred to as anidentifier.
metacharacter
A character that, when unquoted, separates words. One of the following:

| & ; ( ) < > space tab newline

control operator
A token that performs a control function. It is one of the followingsymbols:

|| & && ; ;; ;& ;;& ( ) | |& <newline>

 

RESERVED WORDS

Reserved words are words that have a special meaning to the shell.The following words are recognized as reserved when unquoted and eitherthe first word of a simple command (seeSHELL GRAMMARbelow) or the third word of acaseorforcommand:

! case coproc do done elif else esac fi for function if in select then until while { } time [[ ]] 

SHELL GRAMMAR

 

Simple Commands

A simple command is a sequence of optional variable assignmentsfollowed by blank-separated words and redirections, andterminated by a control operator. The first wordspecifies the command to be executed, and is passed as argument zero.The remaining words are passed as arguments to the invoked command.

The return value of a simple command is its exit status, or128+n if the command is terminated by signaln. 

Pipelines

A pipeline is a sequence of one or more commands separated byone of the control operators|or |&.The format for a pipeline is:

[time [-p]] [ ! ] command [ [|||&] command2 ... ]

The standard output ofcommandis connected via a pipe to the standard input ofcommand2.This connection is performed before any redirections specified by thecommand (seeREDIRECTIONbelow).If |& is used, command's standard error, in addition to itsstandard output, is connected tocommand2's standard input through the pipe;it is shorthand for 2>&1 |.This implicit redirection of the standard error to the standard output isperformed after any redirections specified by the command.

The return status of a pipeline is the exit status of the lastcommand, unless the pipefail option is enabled.If pipefail is enabled, the pipeline's return status is thevalue of the last (rightmost) command to exit with a non-zero status,or zero if all commands exit successfully.If the reserved word!precedes a pipeline, the exit status of that pipeline is the logicalnegation of the exit status as described above.The shell waits for all commands in the pipeline toterminate before returning a value.

If thetimereserved word precedes a pipeline, the elapsed as well as user andsystem time consumed by its execution are reported when the pipelineterminates.The -p option changes the output format to that specified by POSIX.When the shell is in posix mode, it does not recognizetime as a reserved word if the next token begins with a `-'.TheTIMEFORMATvariable may be set to a format string that specifies how the timinginformation should be displayed; see the description ofTIMEFORMATunderShell Variablesbelow.

When the shell is in posix mode, timemay be followed by a newline. In this case, the shell displays thetotal user and system time consumed by the shell and its children.TheTIMEFORMATvariable may be used to specify the format ofthe time information.

Each command in a pipeline is executed as a separate process (i.e., in asubshell). 

Lists

A list is a sequence of one or more pipelines separated by oneof the operators;,&,&&,or||,and optionally terminated by one of;,&,or<newline>.

Of these list operators,&&and||have equal precedence, followed by;and&,which have equal precedence.

A sequence of one or more newlines may appear in a list insteadof a semicolon to delimit commands.

If a command is terminated by the control operator&,the shell executes the command in the backgroundin a subshell. The shell does not wait for the command tofinish, and the return status is 0. Commands separated by a;are executed sequentially; the shell waits for eachcommand to terminate in turn. The return status is theexit status of the last command executed.

AND and OR lists are sequences of one or more pipelines separated by the&& and || control operators, respectively.AND and OR lists are executed with left associativity.An AND list has the form

command1 && command2

command2is executed if, and only if,command1returns an exit status of zero.

An OR list has the form

command1 || command2

command2is executed if and only ifcommand1returns a non-zero exit status.The return status ofAND and OR lists is the exit status of the last commandexecuted in the list. 

Compound Commands

A compound command is one of the following.In most cases a list in a command's description may be separated fromthe rest of the command by one or more newlines, and may be followed by anewline in place of a semicolon.

(list)
list is executed in a subshell environment (seeCOMMAND EXECUTION ENVIRONMENTbelow).Variable assignments and builtincommands that affect the shell's environment do not remain in effectafter the command completes. The return status is the exit status oflist.
{ list; }
list is simply executed in the current shell environment.list must be terminated with a newline or semicolon.This is known as a group command.The return status is the exit status oflist.Note that unlike the metacharacters ( and ), { and} are reserved words and must occur where a reservedword is permitted to be recognized. Since they do not cause a wordbreak, they must be separated from list by whitespace or anothershell metacharacter.
((expression))
The expression is evaluated according to the rules describedbelow underARITHMETICEVALUATION.If the value of the expression is non-zero, the return status is 0;otherwise the return status is 1. This is exactly equivalent tolet "expression".
[[ expression ]]
Return a status of 0 or 1 depending on the evaluation ofthe conditional expression expression.Expressions are composed of the primaries described below underCONDITIONALEXPRESSIONS.Word splitting and pathname expansion are not performed on the wordsbetween the [[ and ]]; tilde expansion,parameter and variable expansion,arithmetic expansion, command substitution, processsubstitution, and quote removal are performed.Conditional operators such as -f must be unquoted to be recognizedas primaries.

When used with [[, the < and > operators sortlexicographically using the current locale.

When the == and != operators are used, the string to theright of the operator is considered a pattern and matched accordingto the rules described below under Pattern Matching,as if the extglob shell option were enabled.The = operator is equivalent to ==.If thenocasematchshell option is enabled, the match is performed without regard to the caseof alphabetic characters.The return value is 0 if the string matches (==) or does not match(!=) the pattern, and 1 otherwise.Any part of the pattern may be quoted to force the quoted portionto be matched as a string.

An additional binary operator, =~, is available, with the sameprecedence as == and !=.When it is used, the string to the right of the operator is consideredan extended regular expression and matched accordingly (as in regex(3)).The return value is 0 if the string matchesthe pattern, and 1 otherwise.If the regular expression is syntactically incorrect, the conditionalexpression's return value is 2.If thenocasematchshell option is enabled, the match is performed without regard to the caseof alphabetic characters.Any part of the pattern may be quoted to force the quoted portionto be matched as a string.Bracket expressions in regular expressions must be treated carefully,since normal quoting characters lose their meanings between brackets.If the pattern is stored in a shell variable, quoting the variableexpansion forces the entire pattern to be matched as a string.Substrings matched by parenthesized subexpressions within the regularexpression are saved in the array variableBASH_REMATCH.The element ofBASH_REMATCHwith index 0 is the portion of the stringmatching the entire regular expression.The element ofBASH_REMATCHwith index n is the portion of thestring matching the nth parenthesized subexpression.

Expressions may be combined using the following operators, listedin decreasing order of precedence:

( expression )
Returns the value of expression.This may be used to override the normal precedence of operators.
! expression
True ifexpressionis false.
expression1 && expression2
True if bothexpression1andexpression2are true.
expression1 || expression2
True if eitherexpression1orexpression2is true.

The && and ||operators do not evaluate expression2 if the value ofexpression1 is sufficient to determine the return value ofthe entire conditional expression.

for name [ [ in [ word ... ] ] ; ] do list ; done
The list of words following in is expanded, generating a listof items.The variable name is set to each element of this listin turn, and list is executed each time.If the in word is omitted, the for command executeslist once for each positional parameter that is set (seePARAMETERSbelow).The return status is the exit status of the last command that executes.If the expansion of the items following in results in an emptylist, no commands are executed, and the return status is 0.
for (( expr1 ; expr2 ; expr3 )) ; do list ; done
First, the arithmetic expression expr1 is evaluated accordingto the rules described below underARITHMETICEVALUATION.The arithmetic expression expr2 is then evaluated repeatedlyuntil it evaluates to zero.Each time expr2 evaluates to a non-zero value, list isexecuted and the arithmetic expression expr3 is evaluated.If any expression is omitted, it behaves as if it evaluates to 1.The return value is the exit status of the last command in listthat is executed, or false if any of the expressions is invalid.
select name [ in word ] ; do list ; done
The list of words following in is expanded, generating a listof items. The set of expanded words is printed on the standarderror, each preceded by a number. If the inword is omitted, the positional parameters are printed (seePARAMETERSbelow). ThePS3prompt is then displayed and a line read from the standard input.If the line consists of a number corresponding to one ofthe displayed words, then the value ofnameis set to that word. If the line is empty, the words and promptare displayed again. If EOF is read, the command completes. Anyother value read causesnameto be set to null. The line read is saved in the variableREPLY.Thelistis executed after each selection until abreakcommand is executed.The exit status ofselectis the exit status of the last command executed inlist,or zero if no commands were executed.
case word in [ [(] pattern [ | pattern ]
A case command first expands word, and tries to matchit against each pattern in turn, using the same matching rulesas for pathname expansion (seePathname Expansionbelow).The word is expanded using tildeexpansion, parameter and variable expansion, arithmetic expansion,command substitution, process substitution and quote removal.Each pattern examined is expanded using tildeexpansion, parameter and variable expansion, arithmetic expansion,command substitution, and process substitution.If thenocasematchshell option is enabled, the match is performed without regard to the caseof alphabetic characters.When a match is found, the corresponding list is executed.If the ;; operator is used, no subsequent matches are attempted afterthe first pattern match.Using ;& in place of ;; causes execution to continue withthe list associated with the next set of patterns.Using ;;& in place of ;; causes the shell to test the nextpattern list in the statement, if any, and execute any associated liston a successful match.The exit status is zero if nopattern matches. Otherwise, it is the exit status of thelast command executed in list.
if list; then list; [ elif list; then list; ] ... [ else list; ] fi
Theiflistis executed. If its exit status is zero, thethen list is executed. Otherwise, each eliflist is executed in turn, and if its exit status is zero,the corresponding then list is executed and thecommand completes. Otherwise, the else list isexecuted, if present. The exit status is the exit status of thelast command executed, or zero if no condition tested true.
while list-1; do list-2; done
until list-1; do list-2; done
The while command continuously executes the listlist-2 as long as the last command in the list list-1 returnsan exit status of zero. The until command is identicalto the while command, except that the test is negated:list-2is executed as long as the last command inlist-1returns a non-zero exit status.The exit status of the while and until commandsis the exit statusof the last command executed in list-2, or zero ifnone was executed.
 

Coprocesses

A coprocess is a shell command preceded by the coproc reservedword.A coprocess is executed asynchronously in a subshell, as if the commandhad been terminated with the & control operator, with a two-way pipeestablished between the executing shell and the coprocess.

The format for a coprocess is:

coproc [NAME] command [redirections]

This creates a coprocess named NAME.If NAME is not supplied, the default name is COPROC.NAME must not be supplied if command is a simplecommand (see above); otherwise, it is interpreted as the first wordof the simple command.When the coprocess is executed, the shell creates an array variable (seeArraysbelow) named NAME in the context of the executing shell.The standard output ofcommandis connected via a pipe to a file descriptor in the executing shell,and that file descriptor is assigned to NAME[0].The standard input ofcommandis connected via a pipe to a file descriptor in the executing shell,and that file descriptor is assigned to NAME[1].This pipe is established before any redirections specified by thecommand (seeREDIRECTIONbelow).The file descriptors can be utilized as arguments to shell commandsand redirections using standard word expansions.The file descriptors are not available in subshells.The process ID of the shell spawned to execute the coprocess isavailable as the value of the variable NAME_PID.The waitbuiltin command may be used to wait for the coprocess to terminate.

Since the coprocess is created as an asynchronous command,the coproc command always returns success.The return status of a coprocess is the exit status of command. 

Shell Function Definitions

A shell function is an object that is called like a simple command andexecutes a compound command with a new set of positional parameters.Shell functions are declared as follows:

name () compound-command [redirection]
function name [()] compound-command [redirection]
This defines a function named name.The reserved word function is optional.If the function reserved word is supplied, the parentheses are optional.The body of the function is the compound commandcompound-command(see Compound Commands above).That command is usually a list of commands between { and }, butmay be any command listed under Compound Commands above,with one exception: If the function reserved word is used, but theparentheses are not supplied, the braces are required.compound-command is executed whenever name is specified as thename of a simple command.When in posix mode, name may not be the name of one of thePOSIX special builtins.Any redirections (seeREDIRECTIONbelow) specified when a function is defined are performedwhen the function is executed.The exit status of a function definition is zero unless a syntax erroroccurs or a readonly function with the same name already exists.When executed, the exit status of a function is the exit status of thelast command executed in the body. (SeeFUNCTIONSbelow.)
 

COMMENTS

In a non-interactive shell, or an interactive shell in which theinteractive_commentsoption to theshoptbuiltin is enabled (seeSHELL BUILTIN COMMANDSbelow), a word beginning with#causes that word and all remaining characters on that line tobe ignored. An interactive shell without theinteractive_commentsoption enabled does not allow comments. Theinteractive_commentsoption is on by default in interactive shells. 

QUOTING

Quoting is used to remove the special meaning of certaincharacters or words to the shell. Quoting can be used todisable special treatment for special characters, to preventreserved words from being recognized as such, and to preventparameter expansion.

Each of the metacharacters listed above underDEFINITIONShas special meaning to the shell and must be quoted if it is torepresent itself.

When the command history expansion facilities are being used(seeHISTORY EXPANSIONbelow), thehistory expansion character, usually !, must be quotedto prevent history expansion.

There are three quoting mechanisms: theescape character,single quotes, and double quotes.

A non-quoted backslash (\) is theescape character.It preserves the literal value of the next character that follows,with the exception of <newline>. If a \<newline> pairappears, and the backslash is not itself quoted, the \<newline>is treated as a line continuation (that is, it is removed from theinput stream and effectively ignored).

Enclosing characters in single quotes preserves the literal valueof each character within the quotes. A single quote may not occurbetween single quotes, even when preceded by a backslash.

Enclosing characters in double quotes preserves the literal valueof all characters within the quotes, with the exception of$,`,\,and, when history expansion is enabled,!.When the shell is in posix mode, the ! has no special meaningwithin double quotes, even when history expansion is enabled.The characters$and`retain their special meaning within double quotes. The backslashretains its special meaning only when followed by one of the followingcharacters:$,`,",\,or<newline>.A double quote may be quoted within double quotes by preceding it witha backslash.If enabled, history expansion will be performed unless an!appearing in double quotes is escaped using a backslash.The backslash preceding the!is not removed.

The special parameters*and@have special meaning when in doublequotes (seePARAMETERSbelow).

Words of the form $aqstringaq are treated specially. Theword expands to string, with backslash-escaped characters replacedas specified by the ANSI C standard. Backslash escape sequences, ifpresent, are decoded as follows:

\a
alert (bell)
\b
backspace
\e
\E
an escape character
\f
form feed
\n
new line
\r
carriage return
\t
horizontal tab
\v
vertical tab
\\
backslash
\aq
single quote
\dq
double quote
\?
question mark
\nnn
the eight-bit character whose value is the octal value nnn(one to three digits)
\xHH
the eight-bit character whose value is the hexadecimal value HH(one or two hex digits)
\uHHHH
the Unicode (ISO/IEC 10646) character whose value is the hexadecimal valueHHHH (one to four hex digits)
\UHHHHHHHH
the Unicode (ISO/IEC 10646) character whose value is the hexadecimal valueHHHHHHHH (one to eight hex digits)
\cx
a control-x character

The expanded result is single-quoted, as if the dollar sign hadnot been present.

A double-quoted string preceded by a dollar sign ($dqstringdq)will cause the string to be translated according to the current locale.If the current locale is C or POSIX, the dollar signis ignored.If the string is translated and replaced, the replacement isdouble-quoted. 

PARAMETERS

Aparameteris an entity that stores values.It can be aname,a number, or one of the special characters listed below underSpecial Parameters.Avariableis a parameter denoted by aname.A variable has a value and zero or more attributes.Attributes are assigned using thedeclarebuiltin command (seedeclarebelow inSHELLBUILTINCOMMANDS).

A parameter is set if it has been assigned a value. The null string isa valid value. Once a variable is set, it may be unset only by usingtheunsetbuiltin command (seeSHELL BUILTIN COMMANDSbelow).

Avariablemay be assigned to by a statement of the form

name=[value]

Ifvalueis not given, the variable is assigned the null string. Allvaluesundergo tilde expansion, parameter and variable expansion,command substitution, arithmetic expansion, and quoteremoval (seeEXPANSIONbelow). If the variable has itsintegerattribute set, thenvalueis evaluated as an arithmetic expression even if the $((...)) expansion isnot used (seeArithmetic Expansionbelow).Word splitting is not performed, with the exceptionof "$@" as explained below underSpecial Parameters.Pathname expansion is not performed.Assignment statements may also appear as arguments to thealias,declare,typeset,export,readonly,andlocalbuiltin commands (declaration commands).When in posix mode, these builtins may appear in a command afterone or more instances of the command builtin and retain theseassignment statement properties.

In the context where an assignment statement is assigning a valueto a shell variable or array index, the += operator can be used toappend to or add to the variable's previous value.This includes arguments to builtin commands such as declare thataccept assignment statements (declaration commands).When += is applied to a variable for which the integer attribute has beenset, value is evaluated as an arithmetic expression and added to thevariable's current value, which is also evaluated.When += is applied to an array variable using compound assignment (seeArraysbelow), thevariable's value is not unset (as it is when using =), and new values areappended to the array beginning at one greater than the array's maximum index(for indexed arrays) or added as additional key-value pairs in anassociative array.When applied to a string-valued variable, value is expanded andappended to the variable's value.

A variable can be assigned the nameref attribute using the-n option to the declare or local builtin commands(see the descriptions of declare and local below)to create a nameref, or a reference to another variable.This allows variables to be manipulated indirectly.Whenever the nameref variable is referenced, assigned to, unset, or hasits attributes modified (other than using or changing the namerefattribute itself), theoperation is actually performed on the variable specified by the namerefvariable's value.A nameref is commonly used within shell functions to refer to a variablewhose name is passed as an argument to the function.For instance, if a variable name is passed to a shell function as its firstargument, running

declare -n ref=$1

inside the function creates a nameref variable ref whose value isthe variable name passed as the first argument.References and assignments to ref, and changes to its attributes,are treated as references, assignments, and attribute modificationsto the variable whose name was passed as $1.If the control variable in a for loop has the nameref attribute,the list of words can be a list of shell variables, and a name referencewill be established for each word in the list, in turn, when the loop isexecuted.Array variables cannot be given the nameref attribute.However, nameref variables can reference array variables and subscriptedarray variables.Namerefs can be unset using the -n option to the unset builtin.Otherwise, if unset is executed with the name of a nameref variableas an argument, the variable referenced by the nameref variable will be unset. 

Positional Parameters

Apositional parameteris a parameter denoted by one or moredigits, other than the single digit 0. Positional parameters areassigned from the shell's arguments when it is invoked,and may be reassigned using thesetbuiltin command. Positional parameters may not be assigned towith assignment statements. The positional parameters aretemporarily replaced when a shell function is executed (seeFUNCTIONSbelow).

When a positional parameter consisting of more than a singledigit is expanded, it must be enclosed in braces (seeEXPANSIONbelow). 

Special Parameters

The shell treats several parameters specially. These parameters mayonly be referenced; assignment to them is not allowed.

*
Expands to the positional parameters, starting from one.When the expansion is not within double quotes, each positional parameterexpands to a separate word.In contexts where it is performed, those wordsare subject to further word splitting and pathname expansion.When the expansion occurs within double quotes, it expands to a single wordwith the value of each parameter separated by the first character of theIFSspecial variable. That is, "$*" is equivalentto "$1c$2c...", wherecis the first character of the value of theIFSvariable. IfIFSis unset, the parameters are separated by spaces.IfIFSis null, the parameters are joined without intervening separators.
@
Expands to the positional parameters, starting from one. When theexpansion occurs within double quotes, each parameter expands to aseparate word. That is, "$@" is equivalent to"$1" "$2" ...If the double-quoted expansion occurs within a word, the expansion ofthe first parameter is joined with the beginning part of the originalword, and the expansion of the last parameter is joined with the lastpart of the original word.When there are no positional parameters, "$@" and$@expand to nothing (i.e., they are removed).
#
Expands to the number of positional parameters in decimal.
?
Expands to the exit status of the most recently executed foregroundpipeline.
-
Expands to the current option flags as specified upon invocation, by thesetbuiltin command, or those set by the shell itself(such as the-ioption).
$
Expands to the process ID of the shell. In a () subshell, itexpands to the process ID of the current shell, not thesubshell.
!
Expands to the process ID of the job most recently placed into thebackground, whether executed as an asynchronous command or usingthe bg builtin (seeJOB CONTROLbelow).
0
Expands to the name of the shell or shell script. This is set atshell initialization. Ifbashis invoked with a file of commands,$0is set to the name of that file. Ifbashis started with the-coption, then$0is set to the first argument after the string to beexecuted, if one is present. Otherwise, it is setto the filename used to invokebash,as given by argument zero.
_
At shell startup, set to the absolute pathname used to invoke theshell or shell script being executed as passed in the environmentor argument list.Subsequently, expands to the last argument to the previous command,after expansion.Also set to the full pathname used to invoke each command executedand placed in the environment exported to that command.When checking mail, this parameter holds the name of the mail filecurrently being checked.
 

Shell Variables

The following variables are set by the shell:

BASH
Expands to the full filename used to invoke this instance ofbash.
BASHOPTS
A colon-separated list of enabled shell options. Each word inthe list is a valid argument for the-soption to theshoptbuiltin command (seeSHELL BUILTIN COMMANDSbelow). The options appearing inBASHOPTSare those reported asonby shopt.If this variable is in the environment whenbashstarts up, each shell option in the list will be enabled beforereading any startup files.This variable is read-only.
BASHPID
Expands to the process ID of the current bash process.This differs from $$ under certain circumstances, such as subshellsthat do not require bash to be re-initialized.
BASH_ALIASES
An associative array variable whose members correspond to the internallist of aliases as maintained by the alias builtin.Elements added to this array appear in the alias list; however,unsetting array elements currently does not cause aliases to be removedfrom the alias list.IfBASH_ALIASESis unset, it loses its special properties, even if it issubsequently reset.
BASH_ARGC
An array variable whose values are the number of parameters in eachframe of the current bash execution call stack.The number ofparameters to the current subroutine (shell function or script executedwith . or source) is at the top of the stack.When a subroutine is executed, the number of parameters passed is pushed ontoBASH_ARGC.The shell setsBASH_ARGConly when in extended debugging mode (see the description of theextdebugoption to theshoptbuiltin below)
BASH_ARGV
An array variable containing all of the parameters in the current bashexecution call stack. The final parameter of the last subroutine callis at the top of the stack; the first parameter of the initial call isat the bottom. When a subroutine is executed, the parameters suppliedare pushed ontoBASH_ARGV.The shell setsBASH_ARGVonly when in extended debugging mode(see the description of theextdebugoption to theshoptbuiltin below)
BASH_CMDS
An associative array variable whose members correspond to the internalhash table of commands as maintained by the hash builtin.Elements added to this array appear in the hash table; however,unsetting array elements currently does not cause command names to be removedfrom the hash table.IfBASH_CMDSis unset, it loses its special properties, even if it issubsequently reset.
BASH_COMMAND
The command currently being executed or about to be executed, unless theshell is executing a command as the result of a trap,in which case it is the command executing at the time of the trap.
BASH_EXECUTION_STRING
The command argument to the -c invocation option.
BASH_LINENO
An array variable whose members are the line numbers in source fileswhere each corresponding member ofFUNCNAMEwas invoked.${BASH_LINENO[$i]} is the line number in the sourcefile (${BASH_SOURCE[$i+1]}) where${FUNCNAME[$i]} was called(or ${BASH_LINENO[$i-1]} if referenced within anothershell function).UseLINENOto obtain the current line number.
BASH_LOADABLES_PATH
A colon-separated list of directories in which the shell looks fordynamically loadable builtins specified by theenablecommand.
BASH_REMATCH
An array variable whose members are assigned by the =~ binaryoperator to the [[ conditional command.The element with index 0 is the portion of the stringmatching the entire regular expression.The element with index n is the portion of thestring matching the nth parenthesized subexpression.This variable is read-only.
BASH_SOURCE
An array variable whose members are the source filenameswhere the corresponding shell function names in theFUNCNAMEarray variable are defined.The shell function${FUNCNAME[$i]} is defined in the file${BASH_SOURCE[$i]} and called from${BASH_SOURCE[$i+1]}.
BASH_SUBSHELL
Incremented by one within each subshell or subshell environment whenthe shell begins executing in that environment.The initial value is 0.
BASH_VERSINFO
A readonly array variable whose members hold version information forthis instance ofbash.The values assigned to the array members are as follows:

BASH_VERSINFO[0]
The major version number (the release).
BASH_VERSINFO[1]
The minor version number (the version).
BASH_VERSINFO[2]
The patch level.
BASH_VERSINFO[3]
The build version.
BASH_VERSINFO[4]
The release status (e.g., beta1).
BASH_VERSINFO[5]
The value ofMACHTYPE.
BASH_VERSION
Expands to a string describing the version of this instance ofbash.
COMP_CWORD
An index into ${COMP_WORDS} of the word containing the currentcursor position.This variable is available only in shell functions invoked by theprogrammable completion facilities (see Programmable Completionbelow).
COMP_KEY
The key (or final key of a key sequence) used to invoke the currentcompletion function.
COMP_LINE
The current command line.This variable is available only in shell functions and externalcommands invoked by theprogrammable completion facilities (see Programmable Completionbelow).
COMP_POINT
The index of the current cursor position relative to the beginning ofthe 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 externalcommands invoked by theprogrammable completion facilities (see Programmable Completionbelow).
COMP_TYPE
Set to an integer value corresponding to the type of completion attemptedthat caused a completion function to be called:TAB, for normal completion,?, for listing completions after successive tabs,!, for listing alternatives on partial word completion,@, to list completions if the word is not unmodified,or%, for menu completion.This variable is available only in shell functions and externalcommands invoked by theprogrammable completion facilities (see Programmable Completionbelow).
COMP_WORDBREAKS
The set of characters that the readline library treats as wordseparators when performing word completion.IfCOMP_WORDBREAKSis unset, it loses its special properties, even if it issubsequently reset.
COMP_WORDS
An array variable (see Arrays below) consisting of the individualwords in the current command line.The line is split into words as readline would split it, usingCOMP_WORDBREAKSas described above.This variable is available only in shell functions invoked by theprogrammable completion facilities (see Programmable Completionbelow).
COPROC
An array variable (see Arrays below) created to hold the file descriptorsfor output from and input to an unnamed coprocess (see Coprocessesabove).
DIRSTACK
An array variable (seeArraysbelow) containing the current contents of the directory stack.Directories appear in the stack in the order they are displayed by thedirsbuiltin.Assigning to members of this array variable may be used to modifydirectories already in the stack, but thepushdandpopdbuiltins must be used to add and remove directories.Assignment to this variable will not change the current directory.IfDIRSTACKis unset, it loses its special properties, even if it issubsequently reset.
EUID
Expands to the effective user ID of the current user, initialized atshell startup. This variable is readonly.
FUNCNAME
An array variable containing the names of all shell functionscurrently in the execution call stack.The element with index 0 is the name of any currently-executingshell function.The bottom-most element (the one with the highest index) is"main".This variable exists only when a shell function is executing.Assignments toFUNCNAMEhave no effect.IfFUNCNAMEis unset, it loses its special properties, even if it issubsequently reset.

This variable can be used with BASH_LINENO and BASH_SOURCE.Each element of FUNCNAME has corresponding elements inBASH_LINENO and BASH_SOURCE to describe the call stack.For instance, ${FUNCNAME[$i]} was called from the file${BASH_SOURCE[$i+1]} at line number${BASH_LINENO[$i]}.The caller builtin displays the current call stack using thisinformation.

GROUPS
An array variable containing the list of groups of which the currentuser is a member.Assignments toGROUPShave no effect.IfGROUPSis unset, it loses its special properties, even if it issubsequently reset.
HISTCMD
The history number, or index in the history list, of the currentcommand.IfHISTCMDis unset, it loses its special properties, even if it issubsequently reset.
HOSTNAME
Automatically set to the name of the current host.
HOSTTYPE
Automatically set to a string that uniquelydescribes the type of machine on whichbashis executing.The default is system-dependent.
LINENO
Each time this parameter is referenced, the shell substitutesa decimal number representing the current sequential line number(starting with 1) within a script or function. When not in ascript or function, the value substituted is not guaranteed tobe meaningful.IfLINENOis unset, it loses its special properties, even if it issubsequently reset.
MACHTYPE
Automatically set to a string that fully describes the systemtype on whichbashis executing, in the standard GNU cpu-company-system format.The default is system-dependent.
MAPFILE
An array variable (see Arrays below) created to hold the textread by the mapfile builtin when no variable name is supplied.
OLDPWD
The previous working directory as set by thecdcommand.
OPTARG
The value of the last option argument processed by thegetoptsbuiltin command (seeSHELL BUILTIN COMMANDSbelow).
OPTIND
The index of the next argument to be processed by thegetoptsbuiltin command (seeSHELL BUILTIN COMMANDSbelow).
OSTYPE
Automatically set to a string thatdescribes the operating system on whichbashis executing.The default is system-dependent.
PIPESTATUS
An array variable (seeArraysbelow) containing a list of exit status values from the processesin the most-recently-executed foreground pipeline (which maycontain only a single command).
PPID
The process ID of the shell's parent. This variable is readonly.
PWD
The current working directory as set by thecdcommand.
RANDOM
Each time this parameter is referenced, a random integer between0 and 32767 isgenerated. The sequence of random numbers may be initialized by assigninga value toRANDOM.IfRANDOMis unset, it loses its special properties, even if it issubsequently reset.
READLINE_LINE
The contents of thereadlineline buffer, for use with"bind -x"(seeSHELL BUILTIN COMMANDSbelow).
READLINE_POINT
The position of the insertion point in thereadlineline buffer, for use with"bind -x"(seeSHELL BUILTIN COMMANDSbelow).
REPLY
Set to the line of input read by thereadbuiltin command when no arguments are supplied.
SECONDS
Each time this parameter isreferenced, the number of seconds since shell invocation is returned. If avalue is assigned toSECONDS,the value returned upon subsequentreferences isthe number of seconds since the assignment plus the value assigned.IfSECONDSis unset, it loses its special properties, even if it issubsequently reset.
SHELLOPTS
A colon-separated list of enabled shell options. Each word inthe list is a valid argument for the-ooption to thesetbuiltin command (seeSHELL BUILTIN COMMANDSbelow). The options appearing inSHELLOPTSare those reported asonby set -o.If this variable is in the environment whenbashstarts up, each shell option in the list will be enabled beforereading any startup files.This variable is read-only.
SHLVL
Incremented by one each time an instance ofbashis started.
UID
Expands to the user ID of the current user, initialized at shell startup.This variable is readonly.

The following variables are used by the shell. In some cases,bashassigns a default value to a variable; these cases are notedbelow.

BASH_COMPAT
The value is used to set the shell's compatibility level.See the description of the shopt builtin below underSHELL BUILTIN COMMANDSfor a description of the various compatibilitylevels and their effects.The value may be a decimal number (e.g., 4.2) or an integer (e.g., 42)corresponding to the desired compatibility level.If BASH_COMPAT is unset or set to the empty string, the compatibilitylevel is set to the default for the current version.If BASH_COMPAT is set to a value that is not one of the validcompatibility levels, the shell prints an error message and sets thecompatibility level to the default for the current version.The valid compatibility levels correspond to the compatibility optionsaccepted by the shopt builtin described below (for example,compat42 means that 4.2 and 42 are valid values).The current version is also a valid value.
BASH_ENV
If this parameter is set when bash is executing a shell script,its value is interpreted as a filename containing commands toinitialize the shell, as in~/.bashrc.The value ofBASH_ENVis subjected to parameter expansion, command substitution, and arithmeticexpansion before being interpreted as a filename.PATHis not used to search for the resultant filename.
BASH_XTRACEFD
If set to an integer corresponding to a valid file descriptor, bashwill write the trace output generated whenset -xis enabled to that file descriptor.The file descriptor is closed whenBASH_XTRACEFDis unset or assigned a new value.UnsettingBASH_XTRACEFDor assigning it the empty string causes thetrace output to be sent to the standard error.Note that settingBASH_XTRACEFDto 2 (the standard error filedescriptor) and then unsetting it will result in the standard errorbeing closed.
CDPATH
The search path for thecdcommand.This is a colon-separated list of directories in which the shell looksfor destination directories specified by thecdcommand.A sample value is".:~:/usr".
CHILD_MAX
Set the number of exited child status values for the shell to remember.Bash will not allow this value to be decreased below a POSIX-mandatedminimum, and there is a maximum value (currently 8192) that this maynot exceed.The minimum value is system-dependent.
COLUMNS
Used by the select compound command to determine the terminal widthwhen printing selection lists.Automatically set if thecheckwinsizeoption is enabled or in an interactive shell upon receipt of aSIGWINCH.
COMPREPLY
An array variable from which bash reads the possible completionsgenerated by a shell function invoked by the programmable completionfacility (see Programmable Completion below).Each array element contains one possible completion.
EMACS
If bash finds this variable in the environment when the shell startswith value"t",it assumes that the shell is running in an Emacs shell buffer and disablesline editing.
ENV
Similar toBASH_ENV;used when the shell is invoked in POSIX mode.
EXECIGNORE
A colon-separated list of shell patterns (see Pattern Matching)defining the list of filenames to be ignored by command search usingPATH.Files whose full pathnames match one of these patterns are not consideredexecutable files for the purposes of completion and command executionvia PATH lookup.This does not affect the behavior of the [, test, and [[commands.Full pathnames in the command hash table are not subject to EXECIGNORE.Use this variable to ignore shared library files that have the executablebit set, but are not executable files.The pattern matching honors the setting of the extglob shelloption.
FCEDIT
The default editor for thefcbuiltin command.
FIGNORE
A colon-separated list of suffixes to ignore when performingfilename completion (seeREADLINEbelow).A filename whose suffix matches one of the entries in FIGNOREis excluded from the list of matched filenames.A sample value is".o:~".
FUNCNEST
If set to a numeric value greater than 0, defines a maximum functionnesting level. Function invocations that exceed this nesting levelwill cause the current