Take the 2-minute tour ×
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.

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

2 Answers 2

up vote 5 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

 
discard

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.