1

This question already has an answer here:

I have a program that receives an argument and prints it every second:

~# ./myapp 234
234
234
234
234
...  

I want to be able to run it in the background and right after a shell but it must be in one line (I don't want to explain why I need it because I don't want to make the discussion too complicated right now).

This is what I tried and the error I received:

~# bash -c "./myapp 234 &; sh" 
bash: -c: line 0: syntax error near unexpected token `;'
bash: -c: line 0: `./myapp 234 &; sh'

I also tried with && as separator:

~# bash -c "./myapp 234 & && sh" 
bash: -c: line 0: syntax error near unexpected token `&&'
bash: -c: line 0: `./myapp 234 & && sh'

Any idea how I can solve it?

EDIT:
Thanks to @roaima.
I also found a link that talks about it:
How to run a program in background and also using && to execute another command

marked as duplicate by ilkkachu bash Mar 12 at 11:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

& is a statement terminator, so you don't need the ; too.

bash -c "./myapp 234 & sh"

Although I'm not entirely sure why you'd want to run sh from bash. Seems a backwards step to me.

  • Oh cool, thanks. It works. – E235 Mar 12 at 10:52

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