Parsing variables from config file in Bash

Solution 1:

Since your config file is a valid shell script, you can source it into your current shell:

. config_file
echo "Content of VARIABLE1 is $VARIABLE1"
echo "Content of VARIABLE2 is $VARIABLE2"
echo "Content of VARIABLE3 is $VARIABLE3"

Slightly DRYer, but trickier

. config_file
for var in VARIABLE1 VARIABLE2 VARIABLE3; do
    echo "Content of $var is ${!var}"
done

Solution 2:

awk -F\= '{gsub(/"/,"",$2);print "Content of " $1 " is " $2}' <filename>

Just FYI, another pure bash solution

IFS="="
while read -r name value
do
echo "Content of $name is ${value//\"/}"
done < filename