I use a property file that is shared across multiple languages, I use a pair of functions:
load_properties() {
local aline= var= value=
for file in config.properties; do
[ -f $file ] || continue
while read aline; do
aline=${aline//\#*/}
[[ -z $aline ]] && continue
read var value <<<$aline
[[ -z $var ]] && continue
eval __property_$var=\"$value\"
# You can remove the next line if you don't need them exported to subshells
export __property_$var
done <$file
done
}
get_prop() {
local var=$1 key=$2
eval $var=\"\$__property_$key\"
}
load_properties
reads from the config.properties
file populating a set of variables __property_...
for each line in the file, get_prop then allows the setting of a variable based on loaded properties. It works for most of the cases that are needed.
Yes, I do realize there's an eval in there, which makes it unsafe for user input, but it works for what I needed it to do.