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.
What’s with the base64 encoded strings?
$ echo -e “JGNhdCA+IGxpbnV4Y29uY2VwdC50eHQ=”|base64 -d
$cat > linuxconcept.txt
Hi Andrew,
You can use base64 encoded string also.
The command base64 -d is accepting file as an input not data.
satish@LC:/home/satish# base64 -d “JGNhdCA+IGxpbnV4Y29uY2VwdC50eHQ=”
base64: ‘“JGNhdCA+IGxpbnV4Y29uY2VwdC50eHQ=”’: No such file or directory
But if you store same encoded data into a file and use the command it will work fine. i.e.
satish@LC:/home/satish# echo -e “JGNhdCA+IGxpbnV4Y29uY2VwdC50eHQ=” | base64 > test.txt
satish@LC:/home/satish# cat test.txt
4oCcSkdOaGRDQStJR3hwYm5WNFkyOXVZMlZ3ZEM1MGVIUT3igJ0K
satish@LC:/home/satish# base64 -d test.txt
“JGNhdCA+IGxpbnV4Y29uY2VwdC50eHQ=”
satish@LC:/home/satish#