sean finney on 13 Oct 2009 13:52:35 -0700

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

Re: [PLUG] Distinguishing between environment variable with null value and one that is not set


On Tue, Oct 13, 2009 at 03:52:24PM -0400, K.S. Bhaskar wrote:
> It appears that POSIX shell (and bash) have no built-in way to
> distinguish between the case where an environment variable exists with
> a null value and the case where it simply does not exist.  The

this is POSIXly correct afaik:

	sh -u -c 'echo $foo' >/dev/null 2>&1

and has the added benefit of only a single subshell call, putting the result
in the test(1)'able $?.  if you want to get fancy and generalize:

  local varname
  eval 'sh -u -c "echo \$$varname"' >/dev/null 2>&1


Attachment: signature.asc
Description: Digital signature

Philadelphia Linux Users Group         --
Announcements -
General Discussion  --