The simple way to add a Config File to your Bash Scripts

The simple way to add a Config File to your Bash Scripts
Photo by Sai Kiran Anagani / Unsplash

Source lets you add external files/code into your scripts, but is also a convenient way of adding config files, providing you are aware of the risks.

The benefits are that source is extremely quick to run, with memorable syntax.

The risks are that all code in the file(s) you source will be executed, even if you only anticipated the file holding variables.

In short, if there's any chance of anyone else adding/editing the config files (a curious user, perhaps), then source isn't the right option.

Let's say you have a config file (config.ini) that contains your_var=your_val.

In your script, you can use source or the shorthand . syntax

. config.ini
# or: source config.ini

echo $your_var 

>>> your_val

But if anyone can edit config.ini, and they add executable commands... Well just hope they are messing with you and add a relatively painless reboot, rather than rm -rf /. You've been warned!



Great! Next, complete checkout for full access to techbits.io
Welcome back! You've successfully signed in
You've successfully subscribed to techbits.io
Success! Your account is fully activated, you now have access to all content
Success! Your billing info has been updated
Your billing was not updated