how to run a script in back ground within a script

Hi friends,
i have two scripts(call it bg1.ksh and bg2.ksh) which needs to be run parallely on background from a script(call it test1.ksh).then i have to wait till these two back ground job gets finished. and once it is completed , then i have to trigger one more script(call it test2.ksh) within test1.ksh. could you please guide me how to do it?

note: i am working in korn shell(ksh88)

please help. thanks in advance.

#!/bin/sh

./bg1.ksh & # One & on the end means 'run it in the background'.
./bg2.ksh &
wait # This will wait for both of them to finish.

./test2.ksh # This one gets run in the foreground.
1 Like

@corona thanks for your reply. i have two more questions.1> for the above solution, does all four script needs to be in same folder??.. 2> will it work in korn shell?

They are all in the same folder that way, but they don't have to be. You could as easily do relative/path/script.sh & or /absolute/path/to/script.sh & .

And yes, it will work in KSH. It will work in any Bourne-derived shell really, since it only uses basic Bourne features.

1 Like

thanks lot :slight_smile: