The answer to this question puzzled me. "They are all wrong!" was my thought, since I had previously omitted the semicolon in the same or similar cases as the OP, and everything worked fine.
Compound command documentation has shown that these answers are correct:
{ list; }
A list with a semicolon (or new line) is required.
... he talks about grouping commands and a similar thing for loops:
Note that wherever a; appears in the description of the command syntax, it can be replaced by one or more newline characters.
... and all examples use semicolons.
But , in practice, you can freely omit the semicolon when nesting loops, if curly braces, etc., in any order. For instance:
{ if true; then echo; fi }
for i in {1..3}; do if true; then echo "$i"; fi done
{ while true; do if true; then for i in {1..3}; do { echo "$i"; } done fi done }
I tested it on bash 4.1, 4.2, 4.4 and dash 0.5.7, they all work sequentially.
My question is : is this just a feature of the implementation, and I should not rely on it, or a standardized behavior that you can rely on? (Bash docs don't say anything about this case).
source
share