View Single Post

   
  #4 (permalink)  
Old 01-16-2008, 08:39 PM
Kevin Collins
 
Posts: n/a
Default Re: check for existence of environment variable

In article <43a31d62$0$287$dbd4b001@news.wanadoo.nl>, Frank Slootweg wrote:
> pc <chalk@netspace.net.au> wrote:
>> hi all,
>>
>> I am having a problem checking for the existence of an environment
>> variable on an new HP-UX box (11.11) under ksh: This script for
>> example:
>>
>> if [ -n "$MYVAR" ] ; then
>> echo "MYVAR is set"
>> else
>> echo "MYVAR is not set"
>> fi
>>
>> runs under ksh on an older (B.11.00) box but will not run under ksh on
>> this new box (B.11.11).
>>
>> error is: ksh: @: parameter not set

> ^
>
> Why does it says "@"? I.e. what is "@" in your script or in some
> input?
>
> BTW, the code snippet looks OK. It's essential to have quotes around
> $MYVAR in the test ("[ ... ]") statement, in case MYVAR is not set, but,
> if this is the actual code, you have that covered.


The "[ ... ]" is a Bourne-style test, not a Korn shell test ("[[ ... ]]").
There are differences in behavior, although that shouldn't matter in this case.
When coding for ksh, it is best to use "[[ ... ]]".


>> If anyone has any thoughts on this matter it would be much appreciated.
>>
>> TIA
>>
>> eddiec :-)


Kevin

--
Unix Guy Consulting, LLC
Unix and Linux Automation, Shell, Perl and CGI scripting
http://www.unix-guy.com
Reply With Quote