[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: $(()): "?:": false "assignment to non-variable"
From: |
Steffen Nurpmeso |
Subject: |
Re: $(()): "?:": false "assignment to non-variable" |
Date: |
Mon, 11 Jul 2022 15:48:29 +0200 |
User-agent: |
s-nail v14.9.24-273-gc3c8c39786 |
Andreas Schwab wrote in
<mvmpmiblsvn.fsf@suse.de>:
|On Jul 09 2022, Steffen Nurpmeso wrote:
|> $ bash -c 'I=3; echo "$((1?(I*=I):I+=I))";echo $I'
|
|The third operand of ?: cannot contain an assignment expression, thus,
|like in C, this is parsed as `(1?(I*=I):I)+=I'.
..
--End of <mvmpmiblsvn.fsf@suse.de>
Chet Ramey wrote in
<52011ddb-824b-73d0-f1c8-c295ffa1fe59@case.edu>:
|On 7/9/22 5:58 PM, Steffen Nurpmeso wrote:
...
|> $ bash -c 'I=3; echo "$((1?(I*=I):(I+=I)))";echo $I'
|
|The parens override precedence.
|
|> $ bash -c 'I=3; echo "$((1?(I*=I):I+=I))";echo $I'
|> bash: line 1: 1?(I*=I):I+=I: attempted assignment to non-variable \
|> (error token is "+=I")
|
|The normal rules of precedence apply, and the conditional expression on the
|rhs of the `:' can't contain an assignment, since the assignment operator
|has higher precedence.
|
|
|> $ bash -c 'I=3; echo "$((1?I*=I:(I+=I)))";echo $I'
|
|The parens override precedence.
Sorry for the noise then.
And thanks for the explanation. (Assignment has lower.)
--steffen
|
|Der Kragenbaer, The moon bear,
|der holt sich munter he cheerfully and one by one
|einen nach dem anderen runter wa.ks himself off
|(By Robert Gernhardt)