Path: csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: Eli Schwartz Newsgroups: gnu.bash.bug Subject: Re: behavior of arithmetic evaluation operator inside extended test operator Date: Tue, 19 May 2020 14:36:20 -0400 Lines: 154 Approved: bug-bash@gnu.org Message-ID: References: <20200519141033.GU751@eeg.ccf.org> <8f95199f-4315-ed19-d929-3c288b414403@archlinux.org> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="QQCm17DK5JjEWV3BAuwXjUEKoEu3HmtLI" X-Trace: usenet.stanford.edu 1589913399 23484 209.51.188.17 (19 May 2020 18:36:39 GMT) X-Complaints-To: action@cs.stanford.edu To: bug-bash@gnu.org Envelope-to: bug-bash@gnu.org X-Spam-BL-Results: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=orion; t=1589913384; bh=LQY9rPxqCswiKQ004GHsDgZHJSe3lHEcBrTQJRh5GHU=; h=Subject:To:References:From:Date:In-Reply-To; b=O7EQfCZPWo25dsPcqCo1T9LtMipP3/IQXVvysAMJwOZb5KOxWIrBj+28sV30ZQ9aR 0QEHXn3QEuTE8smMiScICWrpkmo29Dcw9n7jfSdqMskpgPKSIHWwmPB3Xh6WFU6Yj7 pPVmYevjrFu1CnGQ3LE6P2MxMz/y1s0RDjMX9WyGZp2ZmR4TKM+z+/iqsA0rVCHHNw h7BoBbHbnVbpROTEIrBJ22DDUTrPJkzlQ/bDtq2y2guhnP00EkDdYi8iZ3fXD4jLYY sQzAtfzmaTU1vMkzrNIV5r2rwBv306S8yLsR2N8U16xaXc3RRnJ8EYmwF/w7wLKLYW LYuhGVfczjHHhEuQDMgdUGAMv9I40gITmbM8HJtKwDR5gHOiKK5JhNMdEs/I0dmL0I SPZMWQ8o3gUEsgnnExtepLW/eEtmLNvZVt0u5wSAiAmTNpO8Q3x94Rxqkk9p8kZ894 8bQKQjGpCeaw2YSaWeiI9Cc5NBetKGSEMAnuzq7GxnJBWI5SP6vRXK4EWQ+7+VSbHs w5fQG72e0fckvuZpiyoHO01ZPSCdpgvb3CgQC4QjbQ9mAr+O+yLCQNIyyJ0WAHJTYs hxhFkHwiMymfLbGBjlE/yqv5mKNiXY1f4I1dyoo9VbHZ4ZcMqjQfp4nEce3YC6Ll5P uxwTqpwXlhdg5ELXA5OuyMQk= X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 In-Reply-To: Received-SPF: pass client-ip=88.198.91.70; envelope-from=eschwartz@archlinux.org; helo=orion.archlinux.org X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/19 14:36:26 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <8f95199f-4315-ed19-d929-3c288b414403@archlinux.org> X-Mailman-Original-References: <20200519141033.GU751@eeg.ccf.org> Xref: csiph.com gnu.bash.bug:16303 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --QQCm17DK5JjEWV3BAuwXjUEKoEu3HmtLI Content-Type: multipart/mixed; boundary="EIy32u7OnHk4TZdeAqeh89SHOee81v1MV" --EIy32u7OnHk4TZdeAqeh89SHOee81v1MV Content-Type: text/plain; charset=utf-8 Content-Language: en-US-large Content-Transfer-Encoding: quoted-printable On 5/19/20 1:34 PM, Inian Vasanth wrote: > Thanks Greg for the explanation. Yes your explanation aligns with my > understanding too. >=20 > My recommendation was to check if this behavior needs to be documented = as a > side-note in this section of > http://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Bash-Co= nditional-Expressions > to > explain that, any other primaries other than the ones mentioned above w= ill > be evaluated as a literal string result. I also tried finding an > explanation in your wiki at > https://mywiki.wooledge.org/BashGuide/TestsAndConditionals, but there > wasn't an explicit point made. The constructs: (list) { list; } [[ expression ]] (( expression )) for name [ [ in [ word ... ] ] ; ] do list ; done for (( expr1 ; expr2 ; expr3 )) ; do list ; done select name [ in word ] ; do list ; done case word in [ [(] pattern [ | pattern ] ... ) list ;; ] ... esac if list; then list; [ elif list; then list; ] ... [ else list; ] fi while list-1; do list-2; done until list-1; do list-2; done are listed as *competing* definitions of "what is a compound command". I don't see anywhere in the definition of "CONDITIONAL EXPRESSIONS" that states you may use completely arbitrary compound commands as the expression within a [[ compound command. It seems to me that "CONDITIONAL EXPRESSIONS" is pretty unambiguously explicit on what constitutes one. Any possible reading which even implies that (( expression )) is valid when nested inside of [[ expression ]] as [[ (( expression )) ]] must also imply that one can do [[ [[ expression ]] ]] or [[ for i in one two three; do cmd; done ]] So I'm completely baffled why this might need further clarification. As for your claim that [[ $(( 100 < 3 )) ]] is doing "undocumented arithmetic evaluation", > Word splitting and pathname expansion are not performed on the words > between the [[ and ]]; tilde expansion, parameter and variable > expansion, arithmetic expansion, command substitution, process > substitution, and quote removal are performed. And as duly noted in the documentation, $(( 100 < 3 )) is Arithmetic Expansion and is being performed on the words inside the [[ and ]]. > explain that, any other primaries other than the ones mentioned above > will be evaluated as a literal string result The documentation *already* states that. Nothing is valid in a conditional expression other than the listed primaries, *but* one of those documented primaries is `[[ string ]]` which is defined to be a primary identical to `[[ -n string ]]`. Only strings are valid for this primary, no exceptions. Other primaries don't even accept strings at all, they accept filenames; filenames just so happen to be a subcategory of strings. The same can be said of the -t primary, which accepts a file descriptor number, which is a subcategory of integers, not strings (you may then argue that an integer is a subcategory of a string), or various primaries which operate on variable names, which are subcategories of strings, etc. etc. The documentation doesn't need changing. People need to realize when they read the documentation that a conditional expression happens after other stages of the shell execution process, and that their understanding of conditional expressions is incomplete if they don't understand where they are permitted to use them and how to use tilde expansion, parameter and variable expansion, arithmetic expansion, command substitution, process substitution, and quote removal in order to preprocess words to then use in a conditional expression. To improve their understanding, they must therefore read the definition of the [[ ]] syntax. Thus, enlightenment shall be obtained. --=20 Eli Schwartz Arch Linux Bug Wrangler and Trusted User --EIy32u7OnHk4TZdeAqeh89SHOee81v1MV-- --QQCm17DK5JjEWV3BAuwXjUEKoEu3HmtLI Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEvSewel70XCra9w4EhIGKaBmvSpsFAl7EJyUACgkQhIGKaBmv SpttQA/9HAT2CEGf28/g+UnPrCopeqg1yVGuzbr/eDzC29/cfpoZ7jjCaB/i4wLx hepOofuCZ4R4IdwFoQ74OKQR96SjLD6fLuR67A2bbldh1+kqHBONX9kGu6Pxs3gS fSw/RXDX6J9NCPz5nmokaZApXaZoQXlql5ysR2Kgn7C37bmfm7kuVBhuKspKhEpx W4+fw4yl3vm9UTXrmQom959PSZZSX/mR700G5uAYr25hnaMRlGng6NwbrTFcab5p XP/YaM/ujluWELLxw/aV5FkMkekDLb1qnosKvMuZ2e2Ec3Q5pqVJU/O1u2ZFMv1P 9abqCBMs72iLVfv2i4jV22LroNW9rYBzSlbyfYzBprly4J4igyx39GpIn9zsax2z OiKQl1bjH11sJpnNFKFof6dXmFlSm1t5/C0j38dunzHk2PIOYp3LoNtoL0KI63nK sw6qH1TcjJbr7TTkGjsuQyXvYERD6zewHBZMTwW4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