I'd like to let the user override some variables I use in an existing script, and I wondered if there were an easy way to do this in a generic way. For example my script is:
LOG_LEVEL="DEBUG"
echo $LOG_LEVEL
Now if I run
./myscript.sh LOG_LEVEL="INFO"
I'd like the LOG_LEVEL variable to be overriden by the parameter value. The underlying question is : is it possible to set a variable value from the variable name. The mechanism I'm asking for would require something like this:
set(varname, value)
LOG_LEVELusing the value of a positional parameter ($1f.e.) andDEBUGas its default value:LOG_LEVEL=${1:-DEBUG}.