diff options
Diffstat (limited to 'devdocs/bash/shell-parameters.html')
| -rw-r--r-- | devdocs/bash/shell-parameters.html | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/devdocs/bash/shell-parameters.html b/devdocs/bash/shell-parameters.html new file mode 100644 index 00000000..9c7e33e3 --- /dev/null +++ b/devdocs/bash/shell-parameters.html @@ -0,0 +1,12 @@ +<h1 class="section">Shell Parameters</h1> <p>A <em>parameter</em> is an entity that stores values. It can be a <code>name</code>, a number, or one of the special characters listed below. A <em>variable</em> is a parameter denoted by a <code>name</code>. A variable has a <code>value</code> and zero or more <code>attributes</code>. Attributes are assigned using the <code>declare</code> builtin command (see the description of the <code>declare</code> builtin in <a href="bash-builtins">Bash Builtin Commands</a>). </p> <p>A parameter is set if it has been assigned a value. The null string is a valid value. Once a variable is set, it may be unset only by using the <code>unset</code> builtin command. </p> <p>A variable may be assigned to by a statement of the form </p> +<div class="example"> <pre class="example">name=[value] +</pre> +</div> <p>If <var>value</var> is not given, the variable is assigned the null string. All <var>value</var>s undergo tilde expansion, parameter and variable expansion, command substitution, arithmetic expansion, and quote removal (see <a href="shell-parameter-expansion">Shell Parameter Expansion</a>). If the variable has its <code>integer</code> attribute set, then <var>value</var> is evaluated as an arithmetic expression even if the <code>$((…))</code> expansion is not used (see <a href="arithmetic-expansion">Arithmetic Expansion</a>). Word splitting and filename expansion are not performed. Assignment statements may also appear as arguments to the <code>alias</code>, <code>declare</code>, <code>typeset</code>, <code>export</code>, <code>readonly</code>, and <code>local</code> builtin commands (<em>declaration</em> commands). When in <small>POSIX</small> mode (see <a href="bash-posix-mode">Bash POSIX Mode</a>), these builtins may appear in a command after one or more instances of the <code>command</code> builtin and retain these assignment statement properties. </p> <p>In the context where an assignment statement is assigning a value to a shell variable or array index (see <a href="arrays">Arrays</a>), the ‘<samp>+=</samp>’ operator can be used to append to or add to the variable’s previous value. This includes arguments to builtin commands such as <code>declare</code> that accept assignment statements (declaration commands). When ‘<samp>+=</samp>’ is applied to a variable for which the <code>integer</code> attribute has been set, <var>value</var> is evaluated as an arithmetic expression and added to the variable’s current value, which is also evaluated. When ‘<samp>+=</samp>’ is applied to an array variable using compound assignment (see <a href="arrays">Arrays</a>), the variable’s value is not unset (as it is when using ‘<samp>=</samp>’), and new values are appended to the array beginning at one greater than the array’s maximum index (for indexed arrays), or added as additional key-value pairs in an associative array. When applied to a string-valued variable, <var>value</var> is expanded and appended to the variable’s value. </p> <p>A variable can be assigned the <code>nameref</code> attribute using the <samp>-n</samp> option to the <code>declare</code> or <code>local</code> builtin commands (see <a href="bash-builtins">Bash Builtin Commands</a>) to create a <em>nameref</em>, or a reference to another variable. This allows variables to be manipulated indirectly. Whenever the nameref variable is referenced, assigned to, unset, or has its attributes modified (other than using or changing the nameref attribute itself), the operation is actually performed on the variable specified by the nameref variable’s value. A nameref is commonly used within shell functions to refer to a variable whose name is passed as an argument to the function. For instance, if a variable name is passed to a shell function as its first argument, running </p> +<div class="example"> <pre class="example">declare -n ref=$1 +</pre> +</div> <p>inside the function creates a nameref variable <code>ref</code> whose value is the variable name passed as the first argument. References and assignments to <code>ref</code>, and changes to its attributes, are treated as references, assignments, and attribute modifications to the variable whose name was passed as <code>$1</code>. </p> <p>If the control variable in a <code>for</code> loop has the nameref attribute, the list of words can be a list of shell variables, and a name reference will be established for each word in the list, in turn, when the loop is executed. Array variables cannot be given the nameref attribute. However, nameref variables can reference array variables and subscripted array variables. Namerefs can be unset using the <samp>-n</samp> option to the <code>unset</code> builtin (see <a href="bourne-shell-builtins">Bourne Shell Builtins</a>). Otherwise, if <code>unset</code> is executed with the name of a nameref variable as an argument, the variable referenced by the nameref variable will be unset. </p> <ul class="section-toc"> <li><a href="positional-parameters" accesskey="1">Positional Parameters</a></li> <li><a href="special-parameters" accesskey="2">Special Parameters</a></li> </ul><div class="_attribution"> + <p class="_attribution-p"> + Copyright © 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.<br>Licensed under the GNU Free Documentation License.<br> + <a href="https://www.gnu.org/software/bash/manual/html_node/Shell-Parameters.html" class="_attribution-link">https://www.gnu.org/software/bash/manual/html_node/Shell-Parameters.html</a> + </p> +</div> |
