Mladen,

On 7/17/13 1:07 PM, Mladen Turk wrote:
> On 07/17/2013 06:05 PM, sebb wrote:
>>
>> Why not use:
>>
>> if [ "$FOO" != "" ]
>>
> 
> Some shells do not allow that (comparing empty strings)

I don't know of a shell where "$FOO" would be unset and yet expand to
some non-zero-length string in a command. If that were the case, ".$FOO"
would then expand to the same non-zero-length string with a dot
pre-pended to it and the comparison wouldn't work, anyway.

In my patch, I used a "-z". I'll remove it if there is significant
concern that it is very non-standard.

Sebb, one reason to use the ".$FOO" trick can be found in O'Reilly's
/Unix Power Tools/. They point out that by testing for "$FOO" like this:

if [ "$FOO" = "somestring" ] ;

You run the risk of $FOO expanding to something like "-z" where it would
not result in a string comparison. I like the use of ".$FOO" (leading
dot) because it avoids this issue, but I think it's moot because of the
availability of the "-z" test.

I couldn't find a man page online for the "test" program (but of course
searching for "test man page" yields completely useless results).

-chris

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to