> Apart from your example above, even simple things like:
>    if [ $f = 'y' ]
> will bomb out if $f is blank.

This is quite an important point for would be shell
scripters. The above reads to most programmers as
"if the contents of variable $f is equal to 'y'"
But in fact what happens is the shell substitutes in
the value of $f before calling the test command.
Hence if $f contains say "x" then the test command
sees  

  [ x = 'y' ] 

and returns false, but if $f is blank then the shell
replacement of $f and the subsequent call of test sees 

    [ = 'y' ] 

and hence the error. You need to put the $f in double
quotes so that the shell still sees $f and does the 
substitution but if $f is blank test still gets a valid
condition,

     [ "" = 'y' ]

HTH (or at least is moderately interesting)

P.


--
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://slug.org.au/lists/listinfo/slug

Reply via email to