Bash – Send task to background in an “if”

bashcontrol flowshell

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?

Best Answer

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
Related Question