Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Why is this?

if true; then sleep 3 &; fi
bash: syntax error near unexpected token `;'

I want to run

sleep 3

in the background so that the command ["sleep 3" is just an example] would run in "paralell" style, so it finishes faster. But I'm getting this:

bash: syntax error near unexpected token `;'

error message. Why? Why can't I send a task to the background?

share|improve this question
What do you think you're testing with the if statement? – glenn jackman Dec 10 '11 at 20:08
up vote 6 down vote accepted

Seems like you don't need to separate commands in that case (& separated them itself).

For example.

$> if true; then (sleep 3; echo ok) &  fi
[1] 14224
$> ok
share|improve this answer

It is because & is already a statement separator, so you should not put ; after this.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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