Using bash, I'm trying to read a .properties file (name=value pairs), assigning an indirect variable reference for each line in the file.
The trick is that a property's value string may contain the name of a property that occurred earlier in the file, and I want the name of the 1st property to be replaced with the value of that property.
Here's what I have so far:
###############sample.properties:###############
basePath=/home/joe
fullPath=${basePath}/data
###############End sample.properties###############
###############PropertyReader.sh###############
#! /bin/bash
declare -a settings
settings=(`cat sample.properties | tr '\n' ' '`)
for setting in "${settings[@]}"; do
echo
echo "line:"
echo ${setting}
declare -a settingString
settingString=(`echo -n ${setting/=/ }`)
eval "${settingString[0]}="'"$settingString[1]"'
echo "result:"
eval 'echo "${settingString[0]}='"${settingString[1]}"'"'
done
###############End PropertyReader.sh###############
###############output###############
line:
basePath=/home/joe
result:
basePath=/home/joe
line:
fullPath=${basePath}/data
result:
fullPath=basePath[1]/data
###############End output###############