Search code examples
bashbackground-process

How to run background process with bash -c


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 "..."


Solution

  • 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.