help-bash
[Top][All Lists]
Advanced

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

How to tell if a variable is global or not within a function?


From: Peng Yu
Subject: How to tell if a variable is global or not within a function?
Date: Wed, 9 Mar 2022 22:49:09 -0600

I can test if a variable defined in a function is global or not like
this. But it is not done within a function. Is there a way to tell if
a variable is global or not within a function via declare -p?

$ function f { declare -g x; declare -p x; }
$ f
declare -- x
$ declare -p x
declare -- x
$ function g { declare y; declare -p y; }
$ g
declare -- y
$ declare -p y
-bash: declare: y: not found

-- 
Regards,
Peng



reply via email to

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