Javatpoint Logo
Javatpoint Logo

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.

Example:

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 config.sh

Shell Scripting Sourcing a config file 1

Script for main.sh

Linux Shell Scripting a config file 2

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.

Shell Scripting Sourcing a config file 3

Look at the above snapshot, on running main.sh file, content of config.sh file is imported via source command.






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA