K.S. Bhaskar on 13 Oct 2009 14:42:08 -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 5:19 PM, Paul L. Snyder <plsnyder@drexel.edu> wrote:

[KSB] <...snip...>

> How about this, which should be POSIX-compliant (and doesn't require a
> subshell):
>
>  % foo=bar
>  % if [[ -z ${foo+isset} ]]; then echo nope; else echo yep; fi
>  yep
>  % foo=''
>  % if [[ -z ${foo+isset} ]]; then echo nope; else echo yep; fi
>  yep
>  % unset foo
>  % if [[ -z ${foo+isset} ]]; then echo nope; else echo yep; fi
>  nope
>
> 'isset' doesn't matter, it could be any non-zero-length string.

[KSB] That's perfect, Paul.  I needed something to run in busybox
(Tiny Core Linux) as well as bash.  Thank you very much.

Regards
-- Bhaskar
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug