# Calling scripts within script

**URL:** <https://community.unix.com/t/calling-scripts-within-script/243031>\
**Category:** Shell Programming and Scripting\
**Created:** [June 22, 2009, 10:55am UTC](https://community.unix.com/t/calling-scripts-within-script/243031 "2009-06-22T10:55:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![baanprog](https://community.unix.com/letter_avatar/baanprog/32/5_5575768a8748004e209b776fc1b2916d.png) [@baanprog](https://community.unix.com/u/baanprog)\
**Post date:** [June 22, 2009, 10:55am UTC](https://community.unix.com/t/calling-scripts-within-script/243031/1 "2009-06-22T10:55:50Z")

</div>

Hi,

I have written a some six scripts to move large files and re-size them. This has been done step by step, taking backup, creating the new files, merging the files, removing the temporary files created.

Since these files are around 500 MB, each step takes somewhere between 1 to 5 mins.

My question is, If I call these scripts in the order I perform the steps in a script, will the control wait for completion of each script or will it goto the next line and call the next script before the other one is complete.

Is there a better way to check and do this.

Thanks

---

<div class="post-metadata">

**Author:** ![jim\_mcnamara](https://community.unix.com/letter_avatar/jim_mcnamara/32/5_5575768a8748004e209b776fc1b2916d.png) [@jim\_mcnamara](https://community.unix.com/u/jim_mcnamara)\
**Post date:** [June 22, 2009, 2:31pm UTC](https://community.unix.com/t/calling-scripts-within-script/243031/2 "2009-06-22T14:31:53Z")

</div>

1. each script will execute - the calling (main) script will wait until the child script completes - or fails.

2. your child scripts should return \> 0 - 1 is a good choice - on failure, zero on success.

3. The parent script should check $? (the return code of the child script) after each script completes

```nohighlight
#!/bin/sh
# main.sh
for i in $@
do
   $i
   if [[$? -ne 0]] ; then
       echo "script $i failed"
       exit 1
   fi
done

```

usage example:

```nohighlight
main.sh script1.sh script2.sh script3.sh

```
