Unreliable configuration variable loading

I am working on a bash prompt project that acts on different states in the directory in which you are currently located.

Now I need to download the mini-configuration from the current directory, which is easy to do with the help . .params.conf, except that this method is extremely unsafe, since anyone who has write access to the directory in which you are located can create and execute a command how are you when you stumble upon a directory with a .params.conf file in it.

What is the best way to load variables from a file? The variables will be mostly in true / false state, so I don't parse them in any way so that it can be executed.

Possible solutions:

  • A loop loading every predefined variable is possible, but I want the code to be readable.

  • Putting the whole file in a bash array would be a better solution, but how can I populate the dict key / value in bash like this?

  • If bash can only upload a file to load variables.

I do not know what the params.conf file format will look like. But I think that the simplest will be one line for each param, separated by a space. One of them on each line: key value that can have space in it.

+3
source share
2 answers

evalit can be very unsafe and can still execute malicious code. Better to use declare:

while read varname value
do
    declare "$varname=$value"
done < .params.conf
+3
source

If your values ​​do not contain quotes, this is pretty simple:

while read varname value ; do
    eval $varname="'$value'"
done < .params.conf

, .

0

All Articles