2

I have a command to start background process

./daemon.sh &

it works okay but when i try to run it the following way

bash -i -c "./daemon.sh & ; ./another_daemon.sh &"

it throws the exception bash: syntax error near unexpected token `;'

Is there any way to start background process(es) with bash -i -c "..."

0

1 Answer 1

6

It's not a -c issue.

You need to lose the ; after the &. The shell syntax doesn't accept a semicolon in conjunction with an ampersand. Either of the following is acceptable

bash -i -c "... ; ..."
bash -i -c "... & ..."

but bash -i -c "... & ; ..." is invalid.

Sign up to request clarification or add additional context in comments.

2 Comments

without ampersand, it works. for instance command bash -i -c "./daemon.sh ; ./another_daemon.sh " runs with no issues
Ampersands and semicolons are both command terminators; using both implies the semicolon terminates an empty command, and bash's syntax doesn't allow empty commands. ./daemon.sh & ./another_daemon & is sufficient.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.