help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: whats wrong with (( a = 8 , a > 4 && a -= 2 || a-- )) , bash: ((: a


From: Reuti
Subject: Re: whats wrong with (( a = 8 , a > 4 && a -= 2 || a-- )) , bash: ((: a = 8 , a > 4 && a -= 2 || a-- : attempted assignment to non-variable (error token is "-= 2 || a-- ")
Date: Thu, 23 Mar 2023 17:07:09 +0100

> Am 23.03.2023 um 16:53 schrieb Bipul kumar <bipul.opensource@gmail.com>:
> 
> Hi Alex,
> 
> It's failing because, what you are doing is compound assignment
>  a -= 2
> which needs to be inside parentheses.
> It works for me.
> (( a = 8 , a > 4 && (a -= 2) || a-- ))
> $ echo $a
> 6

It only evaluates (a -= 2) in the logical AND plus OR expression. This might 
work under certain circumstances, i.e. as long as ( a -= 2 ) is not zero:

$ (( a = 8 , a > 4 && (a -= 8) || a-- ))
$ echo $a
-1

-- Reuti


> source https://www.gnu.org/software/bash/manual/bash.html    search
> "compound assignment"
> 
>    Respectfully,
>    Bipul
>    PUBLIC KEY <http://ix.io/1nWf>
>    97F0 2E08 7DE7 D538 BDFA  B708 86D8 BE27 8196 D466
>                    ** Please excuse brevity and typos. **
> 
> 
> On Thu, Mar 23, 2023 at 4:03 PM alex xmb ratchev <fxmbsw7@gmail.com> wrote:
> 
>> i remember doing && (( code
>> maybe i didnt '=' in action there
>> 
>> (( a = 8 , a > 4 && a -= 2 || a-- ))
>> 
>> bash: ((: a = 8 , a > 4 && a -= 2 || a-- : attempted assignment to
>> non-variable (error token is "-= 2 || a-- ")
>> 
>> 
>> (( a = 8 , a > 4 && a-- && a-- || a-- ))
>> 
>> works
>> a=6
>> 
>> ..
>> i suppose this is a (( lex bug where u didnt include || && in op for =
>> 
>> is it ? :))
>> 
>> greets
>> 

Attachment: signature.asc
Description: Message signed with OpenPGP


reply via email to

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