HiveBrain v1.2.0
Get Started
← Back to all entries
snippetbashTip

local — Declare local variables and give them attributes. See also: `declare`, `export`. More information: <

Submitted by: @import:tldr-pages··
0
Viewed 0 times
commandlocaldeclareandcligivevariables

Problem

How to use the local command: Declare local variables and give them attributes. See also: declare, export. More information: <https://www.gnu.org/software/bash/manual/bash.html#index-local>.

Solution

local — Declare local variables and give them attributes. See also: declare, export. More information: <https://www.gnu.org/software/bash/manual/bash.html#index-local>.

Declare a string variable with the specified value:
local {{variable}}="{{value}}"


Declare an integer variable with the specified value:
local -i {{variable}}="{{value}}"


Declare an array variable with the specified value:
local {{variable}}=({{item_a item_b item_c}})


Declare an associative array variable with the specified value:
local -A {{variable}}=({{[key_a]=item_a [key_b]=item_b [key_c]=item_c}})


Declare a readonly variable with the specified value:
local -r {{variable}}="{{value}}"


Display help:
local --help

Code Snippets

Declare a string variable with the specified value

local {{variable}}="{{value}}"

Declare an integer variable with the specified value

local -i {{variable}}="{{value}}"

Declare an array variable with the specified value

local {{variable}}=({{item_a item_b item_c}})

Declare an associative array variable with the specified value

local -A {{variable}}=({{[key_a]=item_a [key_b]=item_b [key_c]=item_c}})

Declare a readonly variable with the specified value

local -r {{variable}}="{{value}}"

Context

tldr-pages: common/local

Revisions (0)

No revisions yet.