[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: $(( )): binary/unary VAR/NUM inconsistency
From: |
Chet Ramey |
Subject: |
Re: $(( )): binary/unary VAR/NUM inconsistency |
Date: |
Thu, 7 Jul 2022 11:35:50 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 |
On 7/6/22 1:10 PM, Steffen Nurpmeso wrote:
Hello.
'Struggling with a Dijkstra two stack parser i am thankful to be
able to compare against bash that uses a completely different and
correct parser!
I stumbled upon this (bash 5.1.16); i find it "understandable" in
respect to clarity, but inconsistent, and also in hindsight to the
announcement of a forthcoming release i thought i report it quick:
$ bash -c 'I=10; echo $((1++I)); echo $I'
bash: line 1: 1++I: syntax error in expression (error token is "++I")
$ bash -c 'I=10; echo $((1++1)); echo $I'
10
Thanks for the report. Most of these are due to bash trying to be helpful.
The pre/postfix operators are parsed as such when they make sense depending
on what precedes or follows them. For instance, if you have ++I, it's
parsed as a pre-increment; if you have ++1, it's parsed as two unary plus
operators and an integer constant.
(Part of this was an attempt to be backwards compatible when I added the
++ and -- operators, since they weren't present until bash-2.04.)
$ bash -c 'I=10;echo "<$(( +10+++I ))>"'
<21>
unary plus, constant, binary plus operator, pre-increment, variable
$ bash -c 'I=10;echo "<$(( +10+ ++I ))>"'
<21>
same
$ bash -c 'I=10;echo "<$(( +10+ +I ))>"'
<20>
unary plus, constant, binary plus operator, unary plus, variable
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/
- $(( )): binary/unary VAR/NUM inconsistency, Steffen Nurpmeso, 2022/07/06
- Re: $(( )): binary/unary VAR/NUM inconsistency, Andreas Schwab, 2022/07/06
- Re: $(( )): binary/unary VAR/NUM inconsistency,
Chet Ramey <=
- Re: $(( )): binary/unary VAR/NUM inconsistency, Steffen Nurpmeso, 2022/07/07
- Re: $(( )): binary/unary VAR/NUM inconsistency, Chet Ramey, 2022/07/08
- Re: $(( )): binary/unary VAR/NUM inconsistency, Steffen Nurpmeso, 2022/07/08
- Re: $(( )): binary/unary VAR/NUM inconsistency, Steffen Nurpmeso, 2022/07/08
- Re: $(( )): binary/unary VAR/NUM inconsistency, Chet Ramey, 2022/07/08
- Re: $(( )): binary/unary VAR/NUM inconsistency, Martin D Kealey, 2022/07/08
- Re: $(( )): binary/unary VAR/NUM inconsistency, Steffen Nurpmeso, 2022/07/09
- Re: $(( )): binary/unary VAR/NUM inconsistency, Robert Elz, 2022/07/08
- Re: $(( )): binary/unary VAR/NUM inconsistency, Chet Ramey, 2022/07/09