while :; echo 'wtf'; done;
line 1: syntax error near unexpected token 'done'
well i certainly have no idea what's wrong with this line. I don't think is the while :
part, it's supposed to be a while true loop.
CodePudding user response:
The syntax of while
allows multiple commands to be executed to test the condition. Those commands are separated from the commands which are conditionally executed by the keyword do
. Consider the line:
while true; echo 'wtf'; echo foo; do echo bar; done
The "do" is essential. In the above, 3 commands are unconditionally executed. If echo foo
succeeds, then echo bar
will be executed and the loop repeats. If echo foo
fails, the loop terminates. If done
is seen before do
, it is a syntax error.