Peng Yu
2018-12-04 23:25:29 UTC
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"
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
Regards,
Peng