How to Include Bash Script in other Bash Script

As we know the bash script is very very important for System Administrator. They are performing lots of tasks using Bash script.

Today, In this tutorial we will learn how to add a bash script into another Bash script.

We will learn it in 4 simple steps, where we create two simple scripts and use one script into another script.

Step 1 – Create a configuration script
Step 2 – Create the main script
Step 3 – Add configuration script into the main script
Step 4 – Execute the main script

Create a configuration script

configuration

USERNAME="satish" 
EMAIL="satish@linuxconcept.com"

Create the main script

main

#!/bin/bash 
#Including config.sh, set filename with proper path. 

echo Welcome ${USERNAME}! 
echo Your email is ${EMAIL}.

Add configuration script into the main script

main

#!/bin/bash 
#Including config.sh, set filename with proper path. 

source config.sh 
echo Welcome ${USERNAME}! 
echo Your email is ${EMAIL}.

Execute the main script

[root@linuxconcept ~]$ ./main.sh 
Welcome satish! 
Your email is satish@linuxconcept.com.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Related Articles