Shell Scripting Sourcing a config file
Many programs use external configuration files. Use of external configuration files prevents a user from making changes to a script. Config file is added with the help of source command.
If a script is shared in many users and every user need a different configuration file, then instead of changing the script each time simply include the config files.
We have two files, one is parent file (main.sh) and other is configuration file (config.sh). We have to source this configuration file into our parent file.
Script for main.sh
Script for config.sh
Look at the above snapshot, we've included config.sh file with source command.
Note: We can also use ( . config.sh ) command instead of ( source config.sh ) .
Now on running main.sh file, config.sh file is included.
Look at the above snapshot, on running main.sh file, content of config.sh file is imported via source command.