[plug] Shell Scripting Confusion

Steve Baker sbaker at icg.net.au
Wed Feb 9 13:57:47 WST 2000


-----Original Message-----
From: Christian <christian at global.net.au>
To: plug at plug.linux.org.au <plug at plug.linux.org.au>
Date: Wednesday, 9 February 2000 13:27
Subject: Re: [plug] Shell Scripting Confusion


>Mike Holland wrote:
>>
>> On Wed, 9 Feb 2000, Christian wrote:
>
>> When you see the answer you'll want to stick with perl.
>> Shell programming is ugly.
>
>Well, I do really want to stick with Perl but I'm hacking one of the
>scripts on the system so while it's very tempting to just do "perl -e
>'<insert nice, sensible, sane code in here>'", it doesn't look that good
>really, does it? :-)
>
>> > if [ -n $output ]; then
>>
>> Since $output is empty, that evaluates as  "if [ -n ]; then "
>> which ought to at least give an error message?
>>
>> Try:
>>         if [ -n "$output" ]; then
>>
>> I'll bet you're groaning by now.
>
>Hmmm... yeah, a little... but why does $output evaluate to being empty
>whereas "$output" has meaning?  Is it that you require the quotes to
>actually turn it into a string?
>

Actually, it's so that the 'test' command (also known as '[') has an
argument to work with after the -n.  The $output variable is evaluated to an
empty string (all shell vars are strings, BTW, you don't have to turn it
into one) but the way that the shell parses the command means that $output
disappears.

bakes
--
Steve Baker sbaker at icg.net.au - Integra Consulting Group
http://www.icg.net.au
Open your mind, then look at http://www.nexusmagazine.com





More information about the plug mailing list