A way to do multiple statements per bash test && statement

bash

Solution

Simple command grouping should work; the syntax can be a little tricky though.

[[ $Var = 1 ]] && { echo "yes-1"; echo "yes-2"; } || { echo "no-1"; echo "no-2"; }

A few things to note:

Heed @tvm's advice about using an `if-then-else` statement if you do anything more complicated.

Every command inside the braces needs to be terminated with a semi-colon, even the last one.

Each brace must be separated from the surrounding text by spaces on both sides. Braces don't cause word breaks in `bash`, so "{echo" is a single word, "{ echo" is a brace followed by the word "echo".

Problem

Does anyone know of a way to execute multiple statements within a bash test? So if I use: ``` [[ $Var = 1 ]] && echo "yes-1" || echo "no-1" ``` And set `Var=1` then output is: `yes-1` If i set `Var=2` then output is: `no-1` And this work as I expected. But If i try to add another statement to execute in the mix and it doesn't work: ``` [[ $Var = 1 ]] && echo "yes-1";echo "yes-2" || echo "no-1";echo "no-2" ``` Which makes sense as bash sees the command ending at; but... this is not what I want. I've tried grouping and evals and functions and have had failures and successes but I'd really just like to do is have this work on one line. Anyone have any ideas?

Original source