Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #16303
| Path | csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail |
|---|---|
| From | Eli Schwartz <eschwartz@archlinux.org> |
| 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 | <mailman.585.1589913399.3227.bug-bash@gnu.org> (permalink) |
| References | <CADNZbLQ8p9ggi3pzwY1LKk=O2T4_a9W2Awap3bXSzGQxhNN=uQ@mail.gmail.com> <20200519141033.GU751@eeg.ccf.org> <CADNZbLT2Fid=AMyJRPeXifnGKkTX0EcUJRuOcr8radY-jTHcuA@mail.gmail.com> <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 | <CADNZbLT2Fid=AMyJRPeXifnGKkTX0EcUJRuOcr8radY-jTHcuA@mail.gmail.com> |
| 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 <bug-bash.gnu.org> |
| List-Unsubscribe | <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe> |
| List-Archive | <https://lists.gnu.org/archive/html/bug-bash> |
| List-Post | <mailto:bug-bash@gnu.org> |
| List-Help | <mailto:bug-bash-request@gnu.org?subject=help> |
| List-Subscribe | <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe> |
| X-Mailman-Original-Message-ID | <8f95199f-4315-ed19-d929-3c288b414403@archlinux.org> |
| X-Mailman-Original-References | <CADNZbLQ8p9ggi3pzwY1LKk=O2T4_a9W2Awap3bXSzGQxhNN=uQ@mail.gmail.com> <20200519141033.GU751@eeg.ccf.org> <CADNZbLT2Fid=AMyJRPeXifnGKkTX0EcUJRuOcr8radY-jTHcuA@mail.gmail.com> |
| Xref | csiph.com gnu.bash.bug:16303 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
On 5/19/20 1:34 PM, Inian Vasanth wrote:
> Thanks Greg for the explanation. Yes your explanation aligns with my
> understanding too.
>
> 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-Conditional-Expressions
> to
> explain that, any other primaries other than the ones mentioned above will
> 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.
--
Eli Schwartz
Arch Linux Bug Wrangler and Trusted User
Back to gnu.bash.bug | Previous | Next | Find similar
Re: behavior of arithmetic evaluation operator inside extended test operator Eli Schwartz <eschwartz@archlinux.org> - 2020-05-19 14:36 -0400
csiph-web