Bash: syntax error near unexpected token `;'

From Brandonhutchinson.com

Revision as of 20:10, 4 September 2008 by Hutch (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

Trying to background a command within a shell loop? 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