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

Eric Blake <[email protected]>
Newsgroups gmane.comp.sysutils.autoconf.patches
Organization Red Hat, Inc.
Message-ID <[email protected]>
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 http://libvirt.org
signature.asc (application/pgp-signature, 604 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
Comment: Public key at http://people.redhat.com/eblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBCAAGBQJVJb1dAAoJEKeha0olJ0NqzqsH/2I085DhYQQh26ZpfC281OW4
BoeFa47CfW6Okt1WsFwxDX+/8x9rvJQSp5p1Rs3VZ1Cg6/J/UeQT/8DctymNPXvi
JRAojOJ6/mNrh4lW3xk1ZwwHVSL5o4rRJut6Icw8+TnfaOTrIgtiQNHrd+j6kf4L
Gw8QnRlmQ7gdBXvR1v2V24iziazFpVNt/50IRrvqZLDW128K9HWVwltcQA6Uljge
g/oakwQ91LMaop9AbYLKRdaGB8AxYlSJMw6b+CGSdacEIRsMBq15UlvDhRvevLhy
RRVj4LZScYujqSWevJjNREXExpvj44kLLyMGiA1YjfmORVstVgAKRkFHNbaFQOk=
=QR9k
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.