Bash: syntax error near unexpected token `;'

From Brandonhutchinson.com

Jump to: navigation, search

Trying to background a command within a shell loop? I was when I received this error.

e.g.,

# for VAR in 1 2 3 ; do run_program $VAR & ; done
bash: syntax error near unexpected token `;'

The reason is explained here. Both & and ; are line terminators; you only need to specify & before done.

e.g.,

# for VAR in 1 2 3 ; do program $VAR & done
[1] 7810
[2] 7811
[3] 7812
Personal tools