I received the error:

bash: syntax error near unexpected token `;'

due to the following command:

evince foo.pdf bar.pdf &; emacs foo.tex &

I is it illegal to separate commands with ; when using & to background a job? Or is there another reason this didn't work?

Thank you.


You don't need the semicolon. After it's sent to the background it's free to get another command.

evince foo.pdf bar.pdf & emacs foo.tex &
  • 2
    This helped me with an if statement after 2h of swearing. If anyone should need this: if [ $(ps -ef |grep -c '[p]grep') -eq 0 ]; then nohup sleep 5 > /dev/null 2>&1</dev/null & fi – Oktav Oct 15 '13 at 13:07

BTW, the core issue is that (Bourne-derived) shells do not allow empty commands.

";" and "&" are command terminators, meaning fg and bg respectively. So "; ;" (or ";" at the beginning of a line) is also invalid.

(Newline(s) imply ";" if there is a not-yet-terminated command, unless you use "\" to continue the line.)

Languages vary a lot on these policies:

C-derived languages allow empty statements.

Pascal and PERL have separators, not terminators.


No, it's just confused and can't work out quite what you mean.

You need to group the & with the command that you want to put in the background:

$ (evince foo.pdf bar.pdf &); emacs foo.tex &

That works fine. Even more explicit would be:

$ (evince foo.pdf bar.pdf &); (emacs foo.tex &)

Especially if you then wanted to chain more commands after the end as well.

  • 3
    There's no need to spawn a subshell just to justify the use of an unnecessary semi-colon. Parentheses aren't just syntax; they cause extra work to be done. – chepner Jun 8 '12 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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