I got this error bash: syntax error near unexpected token; while running this line: while; do; clear; tree .git; sleep 1; done

I got this line from this video

1 Answer 1


The video shows

while :
    tree .git
    sleep 1

Running that as-is will work. If you want to put all the commands on a single line, you need to write it as

while :; do clear; tree .git; sleep 1; done

You can’t separate do from the following command with ;, and you need the colon (:) following while, which defines the condition (: is the same as true, it always succeeds).

See the looping constructs section of the Bash manual for details.

  • Similarly you don't use a semicolon after keywords of an if statement: if condition_commands; then success_commands; else fail_commands; fi Apr 17, 2019 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.