local

From RaySoft

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

Syntax

local [PARAMETER ...] NAME[=VALUE] [...]

Parameters

Parameter can be any parameter accepted by declare:

-f
Restrict action or display to function names and definitions.
-F
Restrict display to function names only (plus line number and source file when debugging).
-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

~/dev/lib/array.sh

References

  1. 1.0 1.1 bash -c 'help local'