help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] Is there a way to access a global variable once a local vari


From: Peng Yu
Subject: [Help-bash] Is there a way to access a global variable once a local variable with the same name is declared?
Date: Tue, 4 Dec 2018 17:25:29 -0600

Hi,

Is there a way to access a global variable once a local variable with
the same name is declared? Thanks.

$ cat main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:

set -v
function f {
    local x
    declare -p x
    # I like to access the global x as well here.
}
x=1
f
declare -p x

$ ./main.sh
function f {
    local x
    declare -p x
}
x=1
f
declare -- x
declare -p x
declare -- x="1"

-- 
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]