bug-bash
[Top][All Lists]
Advanced

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

Re: Possible bug in bash


From: Lawrence Velázquez
Subject: Re: Possible bug in bash
Date: Fri, 13 May 2022 00:51:49 -0400
User-agent: Cyrus-JMAP/3.7.0-alpha0-591-gfe6c3a2700-fm-20220427.001-gfe6c3a27

On Thu, May 12, 2022, at 11:34 PM, flyingrhino wrote:
> Should the "else" condition after the:  ||  run if the last command in 
> the:  &&  section exits non zero?

Yes.  This behavior is not a bug; ''A && B || C'' is simply not
equivalent to ''if A then B; else C; fi''.

https://mywiki.wooledge.org/BashPitfalls#pf22

> Script:
>
>
> #!/bin/bash
>
> [[ "a" == "a" ]] && \
>      {
>      echo "equal"
>      ls x
>      } || {
>      echo "***** SHOULD NOT DISPLAY 4"
>      }
>
>
> Result:
>
> ./moo.sh
> equal
> ls: cannot access 'x': No such file or directory
> ***** SHOULD NOT DISPLAY 4

This behavior is expected and correct.  There is no bug here.

> BTW, I've checked other conditions as follows and they look ok:
>
> [...]
>
> [[ "a" == "a" ]] && \
>      {
>      echo "equal"
>      } || {
>      echo "***** SHOULD NOT DISPLAY 1"
>      }

This would display "***** SHOULD NOT DISPLAY 1" if ''echo "equal"''
failed for some reason.  (Unlikely but possible.)

-- 
vq



reply via email to

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