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

Re: Test existence of shell variable, bash, csh



On Sat, May 05, 2001 at 02:34:47PM -0700, Karsten M. Self wrote:
> This came up on another list.  The problem involves testing existence of
> a Unix shell variable from another program with limited system
> interaction features.
...
>    $?MYVAR
> 
> ...which allows testing of presence of a variable.
> 
> ...but I'm not aware of a similar bash/korn/bourne feature.  Anyone?

Just as a side note: 'setenv MYVAR "/path:$MYVAR"' will fail in [t]csh
if MYVAR is not defined, hence constructs like

if ( $?MYVAR ) then
    setenv MYVAR "/usr/local/myprog:$MYVAR"
else
    setenv MYVAR "/usr/local/myprog"
endif

Bash will quite happily expand an undefined variable to a null string,
so the test above is not needed at all:

export MYVAR="/path:$MYVAR"

is all you need.

Dima
-- 
E-mail dmaziuk at bmrb dot wisc dot edu (@work) or at crosswinds dot net (@home)
http://www.bmrb.wisc.edu/descript/gpgkey.dmaziuk.ascii -- GnuPG 1.0.4 public key
Well, lusers are technically human.                   -- Red Drag Diva in asr



Reply to: