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

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

In script-1:

source script2.sh

or:

. script2.sh

So – no one command in script-1 will not be proceeded till script2.sh will end all it’s tasks.

Little example.

First script:

$ cat script-1.sh
#!/bin/bash
echo "I'm sccript $0."
echo "Runnig script-2..."

source script-2.sh

echo "script-2.sh finished!"

Second script:

$ cat script-2.sh
#bin/bash
echo "I'm script-2. Running wait operation..."
sleep 2
echo "I'm ended my task."

How it works:

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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)