[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: |
Bipul kumar |
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 23:30:07 +0530 |
>
>
>
>
> *$ (( a = 8 , a > 4 && (a -= 8) || a-- ))$ echo $a-1*
Expected.
a > 4 (Ture) && (a -= 8) (Flase) i.e 8-8 = 0. And 0 is considered false
in boolean expressions so AND(&&) will be False here and it move to OR
part which decrements a by 1, resulting in a being set to -1.
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 10:34 PM alex xmb ratchev <fxmbsw7@gmail.com> wrote:
>
>
> On Thu, Mar 23, 2023, 17:07 Reuti <reuti@staff.uni-marburg.de> wrote:
>
>>
>> > 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
>>
>
> thank you sir
>
> -- 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
>> >>
>>
>>
- 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-- "), (continued)
- 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-- "), Bipul kumar, 2023/03/23
- 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-- "), Bipul kumar, 2023/03/23
- 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-- "), Kerin Millar, 2023/03/23
- 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-- "), alex xmb ratchev, 2023/03/23
- 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-- "), alex xmb ratchev, 2023/03/23
- 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-- "), Bipul kumar, 2023/03/23
- 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-- "), Kerin Millar, 2023/03/23
- 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-- "), alex xmb ratchev, 2023/03/23
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-- "), Reuti, 2023/03/23