[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: What shells fail to work if comparing with "" ?
From: |
Eric Blake |
Subject: |
Re: What shells fail to work if comparing with "" ? |
Date: |
Thu, 10 Feb 2011 14:13:30 -0700 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.7 |
On 02/10/2011 12:40 PM, Ralf Wildenhues wrote:
> Hello David,
>
> * Dr. David Kirkby wrote on Thu, Feb 10, 2011 at 07:56:24PM CET:
>> I know its considered bad practice to check for an empty string with
>> something like:
>>
>> if [ "$STR" = "" ] ; then
>>
>> but what shells do actually break with this, and under what conditions?
>
> It's not shells that break. It's these kinds of issues:
> http://thread.gmane.org/gmane.comp.sysutils.autoconf.general/13706
Ralf pointed out a completely different point from the Solaris /bin/sh
syntax issue - that is, that in autoconf scripts, [ and ] are special to
m4, and require extra effort to use, so you are more portable using:
test "x$STR" = x
than you are using:
[ "x$STR" = x ]
so that m4 doesn't eat the [ and ].
--
Eric Blake address@hidden +1-801-349-2682
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature