For some shell sessions I want to be able to print a warning flag if a shell variable is not set and exported.
It is fairly simple to do something like this to print "Error" in the prompt if SET_ME
is unset or null.
test_var () { test -z "$1" && echo Error; }
PS1='$(test_var "$SET_ME") \$ '
However this fails to flag if I set SET_ME
without exporting it, which is an error that I want to be able to detect. Short of something like $(bash -c 'test -z "$SET_ME" && echo Error;')
or grepping the output of export
, is there a simple check that I can do to test whether SET_ME
has been exported?
A non-POSIX, bash-only solution is completely acceptable.