help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] && precedence


From: Matthew Cengia
Subject: Re: [Help-bash] && precedence
Date: Wed, 9 Aug 2017 22:05:13 +1000

I think it's an order of operation thing. Look what happens when I use
group commands in braces to force order of operation:

address@hidden:tmp$ { true || true ;} && echo hi
hi
address@hidden:tmp$ true || { true && echo hi ;}
address@hidden:tmp$

(Sorry for the multiple messages, folks; I should've thought harder with my
first message!)

On Wed, Aug 9, 2017 at 10:01 PM, Matthew Cengia <address@hidden> wrote:

> Oh, I misread your question; you have the tests in the reverse order. I'm
> not 100% sure about this one; sorry.
>
> On Wed, Aug 9, 2017 at 10:00 PM, Matthew Cengia <address@hidden> wrote:
>
>> According to 'greybot' from #bash on Freenode:
>>
>> > foo && bar || baz is not equivalent to 'if foo; then bar; else baz;
>> fi'. In the former case, baz will happen if *either* foo *or* bar return
>> false. In the latter case, baz will only trigger if foo returns false,
>> regardless of the exit code for bar. See http://mywiki.wooledge.org/Bas
>> hPitfalls
>>
>> On Wed, Aug 9, 2017 at 9:35 PM, Russell Shaw <address@hidden>
>> wrote:
>>
>>> Hi,
>>> When i do:
>>>
>>>   true || echo hi
>>>
>>> there is no "hi" as expected
>>>
>>>
>>> when i do:
>>>
>>>   true || true && echo hi
>>>
>>> i get "hi" echoed. Why does "true && echo hi" get evaluated?
>>>
>>>
>>
>>
>> --
>> Regards,
>> Matthew Cengia
>>
>
>
>
> --
> Regards,
> Matthew Cengia
>



-- 
Regards,
Matthew Cengia


reply via email to

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