Bash – How to determine whether shell variables are exported or not

bashshell

With the Bourne shell family, the shell variables all have upper-case case names; which means you can't tell if a particular variable is an environment variable or not just by looking at its name. How do you determine which Bourne shell variables are local (defined only within the current shell)?

Best Answer

If you want see if a variable is exported or not, use declare:

$ foo=a bar=b
$ export foo
$ declare -p foo bar
declare -x foo="a"
declare -- bar="b"