builtin-option

declare -n / local -n

Bash 4.3+ name reference. Assignment through the reference changes its visible target; use fixed trusted names, avoid collisions and cycles. The reference itself is not an array variable.

Formal Syntax & Structure

bash syntaxbash
declare -n ref=target

Parameters & Attributes

NameTypeDescription
refvariable nameName of the reference variable
targettrusted variable nameTarget resolved in dynamic scope

Return Value

exit status

Bash 4.3+ name reference. Assignment through the reference changes its visible target; use fixed trusted names, avoid collisions and cycles. The reference itself is not an array variable.

Working Example

Example Snippetbash
result=beforeupdate() {    local -n bm_ref=result    bm_ref=after}updateprintf '%s\n' "$result"
Bash Reference