From owner-freebsd-questions@freebsd.org Fri Jan 15 08:09:52 2016 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 87B50A83319 for ; Fri, 15 Jan 2016 08:09:52 +0000 (UTC) (envelope-from matthew@FreeBSD.org) Received: from smtp.infracaninophile.co.uk (smtp.infracaninophile.co.uk [IPv6:2001:8b0:151:1:3cd3:cd67:fafa:3d78]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.infracaninophile.co.uk", Issuer "infracaninophile.co.uk" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 2E3631A4C for ; Fri, 15 Jan 2016 08:09:52 +0000 (UTC) (envelope-from matthew@FreeBSD.org) Received: from liminal.local (liminal.infracaninophile.co.uk [IPv6:2001:8b0:151:1:3636:3bff:fed4:b0d6]) (authenticated bits=0) by smtp.infracaninophile.co.uk (8.15.2/8.15.2) with ESMTPSA id u0F89lnW003835 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO) for ; Fri, 15 Jan 2016 08:09:47 GMT (envelope-from matthew@FreeBSD.org) Authentication-Results: smtp.infracaninophile.co.uk; dmarc=none header.from=FreeBSD.org DKIM-Filter: OpenDKIM Filter v2.10.3 smtp.infracaninophile.co.uk u0F89lnW003835 Authentication-Results: smtp.infracaninophile.co.uk/u0F89lnW003835; dkim=none; dkim-atps=neutral X-Authentication-Warning: lucid-nonsense.infracaninophile.co.uk: Host liminal.infracaninophile.co.uk [IPv6:2001:8b0:151:1:3636:3bff:fed4:b0d6] claimed to be liminal.local Subject: Re: Sh-test, bug or not? To: freebsd-questions@freebsd.org References: <0LwGDy-1a6CqZ3TAs-0186MD@mail.gmx.com> From: Matthew Seaman X-Enigmail-Draft-Status: N1110 Message-ID: <5698A94A.8040604@FreeBSD.org> Date: Fri, 15 Jan 2016 08:09:46 +0000 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <0LwGDy-1a6CqZ3TAs-0186MD@mail.gmx.com> Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="LjohoUlgWlt5HIgDPuNcQJ7R0tljmO53F" X-Virus-Scanned: clamav-milter 0.99 at lucid-nonsense.infracaninophile.co.uk X-Virus-Status: Clean X-Spam-Status: No, score=-2.6 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on lucid-nonsense.infracaninophile.co.uk X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Jan 2016 08:09:52 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --LjohoUlgWlt5HIgDPuNcQJ7R0tljmO53F Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable On 15/01/2016 04:32, CK wrote: > If you have authoritative knowledge on the subject, > please state if this functionality is correct: >=20 > $ [ ! "" -a "" ] && echo pass || echo fail > pass > $ [ ! 11 -a "" ] && echo pass || echo fail > pass >=20 > The "-a" operator binds stronger than the "!" operator. > Intuition based on functionality in awk/C would suppose > that the "!" operator would bind stronger than the "-a" > operator, especially since "-a" does in fact have higher > precedence than the "-o" operator, as in awk/C. >=20 > In order to make it work as "expected", it gets ugly: >=20 > $ [ ! "" -a "" ] && echo pass || echo fail > pass > $ [ \( ! "" \) -a "" ] && echo pass || echo fail > fail >=20 > $ [ ! 11 -a "" ] && echo pass || echo fail > pass > $ [ \( ! 11 \) -a "" ] && echo pass || echo fail > fail >=20 > I never noticed this in 20 years, so I don't know if it always > worked this way, or if something changed in my upgrade from > 4.11 to 9.3. I think that while unexpected in comparison to other languages which have inherited C-like operator precedence rules, this is according to the POSIX standard for test(1). As the man page says: The test grammar is inherently ambiguous. In order to assure a degree of consistency, the cases described in the IEEE Std 1003.2 (``POSIX.2''= ), section D11.2/4.62.4, standard are evaluated consistently according = to the rules specified in the standards document. All other cases are sub- ject to the ambiguity in the command semantics. and it notes that the ambiguous cases are those involving (), -a and -o. Your test might be more clearly expressed as: $ [ ! "" ] && [ "" ] && echo pass || echo fail fail (although I'd recommend the -z and -n operators for testing the emptiness / undefinedness or not of strings.) Cheers, Matthew --LjohoUlgWlt5HIgDPuNcQJ7R0tljmO53F Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2 iQJ8BAEBCgBmBQJWmKlLXxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25zLm9w ZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXQ2NTNBNjhCOTEzQTRFNkNGM0UxRTEzMjZC QjIzQUY1MThFMUE0MDEzAAoJELsjr1GOGkAThVIP/0fVK41bLNk2MPU63G1y4Kkp MSTogMyadziO9y8gYS4Z7e4woqPIVyJXNcEi1PydosE6ijqsEeEpW/99IjqPwnmt t66qtqwgc1qs55KBJjOi07IVfckKfkpkSyJUDP0XUrb9gl+Cc9Wk4WUaQ7zQa36j i/S6z6IHpwL1AtgC5iAOBrSFthtFCynCCT8ajntavNImRIdMs61Iow6tnbc2PZik ZwVRStc2F5qJD5B/W6WqWKM794DYF80YGv+2uc64045+rVOmNVjqQPR9vf4hp+5Y 98r3/KxLEZu1x8YqfSShDDqBvgyBFImAzMg+9LX/lml4EMW9IQQaU+GlDC3Yfz/0 dfMcFBIwdUzVbcqsWuYUSFxEcC/UvxDZSaIm5/X+HWm4ve6q3f5dFtahOwL3KFhh 7d1HCv6zOJQozXqrjO1pZXEpjGUdl1pEcsYU5mzw6sAk0QFYM64zTp4hJe6mFHhy eNC+PHilYh0bJNyahVpFvqn+CP8G2olt38EZAFNN4QozPP2xBJfmAYdqPf1PAdyH trmqf3MPtk5jPfwtuhJpkMEMcjRgfQ1LVcvA1fM9Y1qA0npGTONUNtrsJY9wf9NB VCdHUGNsvycYgH/1hQlMvWXPzcN5tnmVzy0QMXTbLQJIqjHlKtuMgdH62g/5OvBw xb7KG/asHmDNJ3BcE8dJ =Q0Ke -----END PGP SIGNATURE----- --LjohoUlgWlt5HIgDPuNcQJ7R0tljmO53F--