Roy Posted on Dec 8, 2020 cmd1 && cmd2 || cmd3 is not the same as if cmd1; then cmd2; else cmd3;fi #bash http://mywiki.wooledge.org/BashPitfalls#pf22 Top comments (2) Subscribe Personal Trusted User Create template Templates let you quickly answer FAQs or store snippets for re-use. Submit Preview Dismiss Collapse Expand Ian Pride Ian Pride Ian Pride Follow You do not want to follow me. I'm a master gatekeeper and web devs aren't programmers. 😛 Location Decatur, Ill, U.S. of A. Education Some college; Self taught Work Command Line Programmer, Scripter at Self Joined Jul 8, 2019 • Dec 8 '20 Dropdown menu Copy link Hide That's a superb reference page, by the way; appreciate the link. I do know most of what's there, but it's always awesome to have compilations of useful use-case's and fixes of common caveats/pitfalls. Collapse Expand Geoffrey R. Scheller Geoffrey R. Scheller Geoffrey R. Scheller Follow MS Physics; MS Mathematics. Computer Science Hobbyist. Linux/BSD Enthusiast. Email geoffrey@scheller.com Location Colorado Springs CO; Lehigh Valley PA Education MS Physics; MS Mathematics Work Research Scientist at Air Force Research Labs Joined Dec 8, 2020 • Dec 8 '20 Dropdown menu Copy link Hide $ [[ x == x ]] || [[ x == y ]] && [[ x == y ]] $ echo $? 1 $ [[ x == x || x == y && x == y ]] $ echo $? 0 Outside of [[ ]], && and || have equal pressidence. Code of Conduct • Report abuse Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well Confirm For further actions, you may consider blocking this person and/or reporting abuse
Top comments (2)
That's a superb reference page, by the way; appreciate the link. I do know most of what's there, but it's always awesome to have compilations of useful use-case's and fixes of common caveats/pitfalls.
$ [[ x == x ]] || [[ x == y ]] && [[ x == y ]]
$ echo $?
1
$ [[ x == x || x == y && x == y ]]
$ echo $?
0
Outside of [[ ]], && and || have equal pressidence.