Why does ; after & lead to unexpected token error in bash on Linux?

The command using ';' after '&' like

ssh host1 hostname &; ssh host2 hostname &

Leads to error like

bash: syntax error near unexpected token `;'

Why does ; after & lead to unexpected token error in bash on Linux? And what's the solution?

asked Dec 10, 2015 by anonymous

1 Answer

The fix

The quick fix is to change your command to

ssh host1 hostname & ssh host2 hostname &

The reason

";" and "&" are command terminators (newline(s) imply ";" unless there is a "\" to continue the line) and Bash does not allow empty commands.

&; means start the previous command in background (&) and the start a ; command in foreground. The later one is empty and is not allowed by Bash.

answered Dec 17, 2015 by Eric Z Ma (44,280 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...