2

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

E235
  • 383

1 Answers1

3

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

Chris Davies
  • 116,213
  • 16
  • 160
  • 287