[Top][All Lists]

[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
 |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
 |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.)

|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)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]