Statements and blocks
In the terminalela --spec statements-and-blocks
- A newline ends a statement.
- A semicolon is only used to put two statements on one line.
- Indentation is not significant.
- A keyword (
if,for,while,switch,with,proc,struct,enum,catch, anddeferalone on its line) opens a block;endcloses it. - Bash's block ends,
fi,doneandesac, are errors that say to writeend. Since a line that starts withdoneis one,donenames nothing: a variable, a loop variable, a parameter or a named result calleddonestops the script before line 1, with'done' is reserved, as ela refuses bash's 'done', so it can't be a variable: call it something else, such as 'finished'. endmay be followed by an optional label:end if,end for,end while,end switch,end with,end proc,end struct,end enum,end catch,end defer. If a label is present, the parser checks that it matches the block.- One line.
if,for,while,with,catch,deferandproctake their body on their own line, after a;, andstructandenumtheir fields and values,;between them; the line's end closes it; anendon the line closes it too.elseandelse ifgo on the same line, and so does a block inside such a body. A;with nothing after it on the line starts no body:if $ok;and the body below is a block as any other. - A body begun on its header's line stays on it: a line after it is not in the block,
endorelseon a later line is an error that says so, andela --lintwarns of a line indented under one.switchandcasetake their body on the lines below.
if $a == $b; echo samefor f in *.log; rm $fif $n < 0; echo negative; else if $n == 0; echo zero; else; echo positivefor x in $xs; if $x > 1; echo $xenum Level; LOW; MID; HIGHcatch signal INT TERM; exit 130proc paid(r); return $r["paid"]
A statement continues onto the next line if the line ends with an open bracket ((, [, {, $(), a comma, a pipe or = with a space before it, or if the next line starts with and or or. A = glued to a word (key=) and a rule of = signs (=====) are words of a command, and end their line; a lone = at the end of a command's line is an error, since the next line would be more of its words: write '='. A line that is a name and = alone, echo =, is an assignment whose value is the line below, so a command there is an error at the = that says to write echo '='. A line ending in and or or is an error. Newlines inside brackets are ignored. Brackets, captures, strings inside ${ } and blocks nest at most 1000 levels deep. Arithmetic and comparison operators do not continue a line, because cd -, cd / and ls * are valid line endings, so a line ending in one is an error; wrap long arithmetic in brackets instead. No backslashes.
if file.exists($path) and $size > 0 or $force echo "go"end if