Eric Blake wrote: > env is required by POSIX, but it is not (yet) listed in the list of > programs safe to use in GNU Coding Standards
And 'env' would not help much, because its output can easily be confused by environment variable values that contain newlines: $ foo='not POSIXLY_CORRECT=1' $ export foo $ env | grep POSIXLY_CORRECT POSIXLY_CORRECT=1 $ echo ${POSIXLY_CORRECT+set} > Any other ideas for portable ways of detecting whether a shell variable > is currently local-only or exported? 'printenv' does not exist on Solaris. But 'awk' is among the list of portable programs. This should work: if test `awk 'BEGIN { print ENVIRON["POSIXLY_CORRECT"] }' < /dev/null | wc -c` = 1; then : # POSIXLY_CORRECT is not exported else : # POSIXLY_CORRECT is exported fi Maybe the test whether the value of ENVIRON["POSIXLY_CORRECT"] is empty or non-empty can be moved into the awk script. I'm not very familiar with awk programming. Bruno