local
Create a local variable called NAME, and give it VALUE.[1]
Local variables can only be used within a function; they are visible only to the function where they are defined and its children.[1]
Documentation
- local [EN] @ GNU Bash Reference Manual
- bash -c 'help local'
- man 1 'bash' [EN]
Syntax
local [PARAMETER ...] NAME[=VALUE] [...]
Parameters
Parameter can be any parameter accepted by declare:
- -p
- Display the attributes and value of each NAME.
Set attributes
- -a
- To make NAMEs indexed arrays.
- -A
- To make NAMEs associative arrays.
- -n
- To make NAME a reference to the variable named by its value.
- -r
- To make NAMEs readonly.
- -x
- To make NAMEs export.
Examples
- Reference to a variable outside a function