[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Replace 'test "${var+set}" = set' with 'test -n "${var+set}"

From: Eric Blake
Subject: Re: [PATCH] Replace 'test "${var+set}" = set' with 'test -n "${var+set}"'
Date: Wed, 08 Apr 2015 17:44:29 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0

On 04/08/2015 04:25 PM, Eric Blake wrote:
> And in modern shell, 'test -n ...' is strictly equivalent to 'test ...'
> (not so in ancient shell, but those are getting fewer and farther
> between) - if we did appropriate pre-filtering tests, we could get away
> with 15 bytes:
> test "${var+y}"

Or even 13:

test ${var+y}

Does anyone know of portability flaws in broken test implementations
that might bite us? This one actually works on Solaris /bin/sh, without
affecting $?.

> On 04/08/2015 03:11 PM, Paul Eggert wrote:
>> Isn't '${var+:} false' faster yet?
>          ^^^^^^^^^^^^^^  14 bytes

and shorter than Paul's solution.  But I'm worried if some other shell
mis-handles it.

Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]