Thanks Lawrence for the response. Between you and Robert I now have a clear understanding on this and I'll go back and fix the bug in my code which used this construct.
Ken. On Fri, 13 May 2022 00:51:49 -0400 Lawrence Velázquez <v...@larryv.me> wrote: > 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.) > -- Rhinos can fly, It's just a case of mind over matter ... ... And you need a lot of mind to control that much matter ...