I have one of configuration file e.g. called (abc.conf)
abc.conf
-------
location1=/opt/test1/locationx
location2=/opt/test1/locationy
location3=/opt/test1/locationz
I have sample code which works fine if I am not using such path and slashes
getProperty()
{
PROPERTY_FILE=$1
PROP_KEY=$2
PROP_VALUE=`cat $PROPERTY_FILE | grep -w "$PROP_KEY" | cut -d'=' -f2`
echo $PROP_VALUE
}
Using like
VALUE=$(getProperty $CONF_FILE $LOCATION1)
But this function have limitation using it, when I use it like to fetch location1 it also fetches location2/location3 like similar location together instead specific key value only. it should work with unique value only.
question from:
https://stackoverflow.com/questions/65844954/read-key-value-from-file-using-shell-script 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…