1

Bash evaluates the logical operators such that && always takes precedence. So for example:

false || echo 1 && echo 2
1
2

and

true || echo 1 && echo 2
2

Ok. So lets say I want the output to be like this:

false || (echo 1 && echo 2)

But without invoking a subshell.

The only solution I could think of is this:

false || if true; then echo 1; echo 2; fi
1
2

Is there any cleaner way, similar to parenthesis in C, to group commands together without having to invoke a subshell?

  • In retrospect, this should probably have been posted on stackoverflow. – Zhro Oct 28 '14 at 10:53
  • No, it's also fine to ask here. – slhck Oct 28 '14 at 11:22
2
false || { echo 1 && echo 2; }
  • This seems to be accurate. No parallel processing subshell is created when I do this: { sleep 0.2s; echo 1; } || { echo 1 && echo 2; } – Zhro Oct 28 '14 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.