[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: POSIXLY_CORRECT not correctly unset in getopt.m4?
From: |
Bruno Haible |
Subject: |
Re: POSIXLY_CORRECT not correctly unset in getopt.m4? |
Date: |
Tue, 7 Sep 2010 22:09:18 +0200 |
User-agent: |
KMail/1.9.9 |
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