1 1 3.4 Shell Parameters 1 ==================== 1
1 · Positional Parameters The shell's command-line arguments. · Special Parameters Parameters denoted by special characters. 1 1 A PARAMETER is an entity that stores values. It can be a 'name', a 1 number, or one of the special characters listed below. A VARIABLE is a 1 parameter denoted by a 'name'. A variable has a VALUE and zero or more 1 ATTRIBUTES. Attributes are assigned using the 'declare' builtin command 1 (see the description of the 'declare' builtin in ⇒Bash Builtins). 1 1 A parameter is set if it has been assigned a value. The null string 1 is a valid value. Once a variable is set, it may be unset only by using 1 the 'unset' builtin command. 1 1 A variable may be assigned to by a statement of the form 1 NAME=[VALUE] 1 If VALUE is not given, the variable is assigned the null string. All 1 VALUEs undergo tilde expansion, parameter and variable expansion, 1 command substitution, arithmetic expansion, and quote removal (detailed 1 below). If the variable has its 'integer' attribute set, then VALUE is 1 evaluated as an arithmetic expression even if the '$((...))' expansion 1 is not used (⇒Arithmetic Expansion). Word splitting is not 1 performed, with the exception of '"$@"' as explained below. Filename 1 expansion is not performed. Assignment statements may also appear as 1 arguments to the 'alias', 'declare', 'typeset', 'export', 'readonly', 1 and 'local' builtin commands (DECLARATION commands). When in POSIX mode 1 (⇒Bash POSIX Mode), these builtins may appear in a command after 1 one or more instances of the 'command' builtin and retain these 1 assignment statement properties. 1 1 In the context where an assignment statement is assigning a value to 1 a shell variable or array index (⇒Arrays), the '+=' operator can 1 be used to append to or add to the variable's previous value. This 1 includes arguments to builtin commands such as 'declare' that accept 1 assignment statements (DECLARATION commands). When '+=' is applied to a 1 variable for which the INTEGER attribute has been set, VALUE is 1 evaluated as an arithmetic expression and added to the variable's 1 current value, which is also evaluated. When '+=' is applied to an 1 array variable using compound assignment (⇒Arrays), the 1 variable's value is not unset (as it is when using '='), and new values 1 are appended to the array beginning at one greater than the array's 1 maximum index (for indexed arrays), or added as additional key-value 1 pairs in an associative array. When applied to a string-valued 1 variable, VALUE is expanded and appended to the variable's value. 1 1 A variable can be assigned the NAMEREF attribute using the '-n' 11 option to the 'declare' or 'local' builtin commands (⇒Bash Builtins) to create a NAMEREF, or a reference to another variable. 1 This allows variables to be manipulated indirectly. Whenever the 1 nameref variable is referenced, assigned to, unset, or has its 1 attributes modified (other than using or changing the nameref attribute 1 itself), the operation is actually performed on the variable specified 1 by the nameref variable's value. A nameref is commonly used within 1 shell functions to refer to a variable whose name is passed as an 1 argument to the function. For instance, if a variable name is passed to 1 a shell function as its first argument, running 1 declare -n ref=$1 1 inside the function creates a nameref variable REF whose value is the 1 variable name passed as the first argument. References and assignments 1 to REF, and changes to its attributes, are treated as references, 1 assignments, and attribute modifications to the variable whose name was 1 passed as '$1'. 1 1 If the control variable in a 'for' loop has the nameref attribute, 1 the list of words can be a list of shell variables, and a name reference 1 will be established for each word in the list, in turn, when the loop is 1 executed. Array variables cannot be given the nameref attribute. 1 However, nameref variables can reference array variables and subscripted 1 array variables. Namerefs can be unset using the '-n' option to the 1 'unset' builtin (⇒Bourne Shell Builtins). Otherwise, if 'unset' 1 is executed with the name of a nameref variable as an argument, the 1 variable referenced by the nameref variable will be unset. 1