1

I have 3 sh scripts in 3 different directories.

Instead of going into each directory and executing each script I wanted to trigger all 3 scripts from one central script (located in the superfolder above).

I tried using /bin/bash /path/to/script but this would assume the superfolder location as the location to work in.

Therefore I tried going into each folder first cd folder1 before execution but that would not work either.

I just want to trigger those 3 scripts without changing its local environment

1
  • What exactly didn't work using cd folder1? There is no difference between executing that command in the parent script and changing to the folder in your interactive shell before starting the child manually, unless you have some sort of alias or wrapper around the built-in cd command. Commented May 23, 2017 at 13:09

3 Answers 3

3

Please try the following:

( cd dir1; ./script1 )
( cd dir2; ./script2 )
( cd dir3; ./script3 )

Note that () are needed to save/restore you master script current directory.

Sign up to request clarification or add additional context in comments.

1 Comment

No need to spawn an additional process. You could do as well cd dir1; ./script1; cd - etc.
0

Using a sub-shell, when sub-shell exits the current shell is not changed

( cd path ; ./script )

Comments

0

The *nix way to do this is to run the scripts with their full or relative paths as you did originally. The scripts should ideally do the same thing no matter what PWD was for the original user. If you really need to know the working directory of the script, for reasons like sourcing neighboring files, just beware that it adds a bit of complexity and may not work in ancient Bash versions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.