Say I have this structure


In masterscript I spawn the other scripts as background processes:

"/a/script1" &
"/a/b/script2" &

The problem is that script1 and script2 inherit the working directory of masterscript. Is there a way to start these scripts with working directories the directories where they are?

  • Why not? Change the working directory to whatever you want and then start the script. cd /a/ && ./script1. Or did I misunderstand the question? – Dmitry Alexandrov Aug 29 '14 at 13:47
(cd /a   && ./script1)&
(cd /a/b && ./script2)&

If the names don't contain spaces or special characters like *, (, or ), you don't need quotes.

  • 4
    I'd recommend the form ( cd /foo && exec ./script ) &. Otherwise you leave a shell laying around for every single one of these. – Patrick Aug 29 '14 at 14:20

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.