-2

If I call a shell script (inner.sh) inside another shell script (main.sh), the first script (main.sh) will wait the end of inner.sh before continue. If inner.sh fails, main.sh fails too.

Eg:

cat .main.sh
#!/bin/bash 
bin/bash .inner.sh

main.sh will end only after inner.sh ends.

How do I run inner.sh in a separated process (not subprocess, not same process and not in parallel with main.sh)?

What I want to do is make main.sh continue execution no matter what happens with inner.sh.

  • 3
    /bin/bash .inner.sh & or nohup /bin/bash .inner.sh & – GypsyCosmonaut Aug 28 '17 at 15:36
  • @GypsyCosmonaut I feel stupid now for not remembering nohup command. I usually use nohup in bash, did not occur to me use inside a script. Thanks – Joao Vitorino Aug 28 '17 at 15:50
  • GypsyCosmonaut. write as answer and I will mark as solved. – Joao Vitorino Aug 28 '17 at 15:50
  • 1
    So by “not … parallel from main.sh”, you mean “in parallel with main.sh”? Your question is hard to follow. – Gilles Aug 28 '17 at 22:38
1

/bin/bash .inner.sh &

runs .inner.sh as a subprocess but .inner.sh would still be a part of the process of .main.sh

but if you want to run .inner.sh as a completely detached process then you might want to do

/bin/bash .inner.sh & disown

or

nohup /bin/bash .inner.sh &

These run .inner.sh as a completely separate process. so even if you ^C out of your .main.sh, your .inner.sh would still run (given that you do ^C after the interpreter executed the disown or nohup).

  • 1
    Can also run as subprocess if put the command between (). (/bin/bash .inner.sh) – Joao Vitorino Aug 28 '17 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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