Bash Script Calls another bash script and waits for it to complete before proceeding


I have 1 bash script that runs another bash script, however the first bashscript isn't waiting for the second one to complete before proceeding, how can I force it to wait?

For example:


#call to secondary script
echo " has completed"

echo "continuing with the rest of"

The way it is now, it will run, and continue on, without waiting for to complete.

2/16/2010 1:24:47 AM

Accepted Answer

Normally it does; something else is happening. Are you sure that the other script isn't running something in the background instead? You can try using wait regardless.

2/16/2010 1:27:06 AM

AS I use scheme like this in few scripts - just calling second scripts in the same shell-copy using source.

In script-1:




So - no one command in script-1 will not be proceeded till will end all it's tasks.

Little example.

First script:

$ cat
echo "I'm sccript $0."
echo "Runnig script-2..."


echo " finished!"

Second script:

$ cat
echo "I'm script-2. Running wait operation..."
sleep 2
echo "I'm ended my task."

How it works:

$ ./
I'm sccript ./
Runnig script-2...
I'm script-2. Running wait operation...
I'm ended my task. finished!

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow