Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash unexpected token when using "&;"

Tags:

bash

ssh

I'm launching a script via SSH with this command:

ssh myuser@myhost "bash -x -c 'source config.sh; nohup Start_JBoss.sh > /dev/null &; sleep 5'"

however I'm hitting an error:

Connecting to: myhost with myuser
Password:
bash: -c: line 0: syntax error near unexpected token `;'
bash: -c: line 0: `source config.sh; nohup Start_JBoss.sh > /dev/null &; sleep 5'

What's I'm doing wrong here? I know that SSH is not the cause as the same command fails into a local shell.

I've read some similar thread where there's some mention on Bash version as culprit for some other kind of unexpected token issue so adding here just for reference in case is needed:

bash -version
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
like image 276
Derek Wildstar Avatar asked Dec 26 '22 13:12

Derek Wildstar


1 Answers

Guess I did not searched hard enough as I found out solution here https://superuser.com/questions/269429/why-did-after-return-an-unexpected-token-error-in-bash but leaving here as reference.

Basically if you send to background a process you do not need to use ; as the shell is already ready to accept new command.

like image 59
Derek Wildstar Avatar answered Jan 11 '23 09:01

Derek Wildstar