Include Files in Bash
Similar to other programming languages which allow to include other files to a file, Bash scripting also allows to include (source) another shell script file to script file.
For example, to include config.sh script to current script file use following syntax, where config.sh is available in the same directory of the current script.
#!/bin/bash source config.sh
Include Shell Script To Other Shell Script
For this example, First, I have created a config.sh file with the following content.
Now create another file backup.sh which includes config.sh file and complete the database backup.
mysqldump -h $MYSQL_HOST -p $MYSQL_PORT -u$MYSQL_USER -p$MYSQL_PASSWORD mydb > mydb.sql
You can also view our real script of advance MySQL database backup where I used to source a file to the backup script.