I would like to group few bash instructions after a condition:
First attempt:
$ [[ 0 == 1 ]] && echo 1; echo 2
2
Second att
Placing commands in ()
creates a subshell in which the grouped commands are executed. That means that any changes to variables made in subshell, stay in subshell, for example
$ n=5; [[ "$n" == "5" ]] && ( ((n++)); echo $n); echo $n
6
5
Instead you want to group with {}
which doesn't invoke a subshell. Then the output would be
$ n=5; [[ "$n" == "5" ]] && { ((n++)); echo $n; }; echo $n
6
6
Also mind the spaces on the inside of {}
and semicolons: { ((n++)); echo $n; };
.