Bourne shell "if" syntax
Tim Daneliuk
tundra at tundraware.com
Mon Jun 10 19:05:46 UTC 2013
On 06/10/2013 01:59 PM, dteske at freebsd.org wrote:
>
>
>> -----Original Message-----
>> From: owner-freebsd-questions at freebsd.org [mailto:owner-freebsd-
>> questions at freebsd.org] On Behalf Of lconrad at go2france.com
>> Sent: Monday, June 10, 2013 11:53 AM
>> To: freebsd-questions at freebsd.org
>> Subject: Bourne shell "if" syntax
>>
>>
>>
>> script fragment:
>>
>> PTR=`dig @some.dns +short +norec -x a.b.c.d`
>>
>> echo "$PTR"
>>
>> if [ "$PTR" == "" ] ; then
>>
>
> if [ "$PTR" = "" ]; then
>
> or
>
> if [ -z "$PTR" ]; then
>
> or
>
> if [ "$PTR" ]; then
>
> but _NOT_
>
> if [ "$PTR" == "" ]; then
>
I work across a bunch of different OSs and shells of many vintages. As I recall,
the -z argument has problems of portability on older/broken shells and/or
is not available in all environments (I cannot recall which at the moment). So
I achieve the same results by using a character sentinel that guarantees that the
comparison always works:
f [ _"$PTR" == _ ] ; then
--
-----------------------------------------------------------------------
Tim Daneliuk
More information about the freebsd-questions
mailing list