Having the following content in a file:
VARIABLE1="Value1"
VARIABLE2="Value2"
VARIABLE3="Value3"
I need a script that outputs the following:
Content of VARIABLE1 is Value1
Content of VARIABLE2 is Value2
Content of VARIABLE3 is Value3
Any ideas?
If you need these...
Features
=
(ievar = value
will not fail);Code
Comments
tr -d '\r' ...
deletes DOS carriage return.! $lhs =~ ^\ *#
skips single line comments and-n $lhs
skips empty lines.Deleting trailing spaces with
${rhs%%*( )}
requires setting extended globbing withshopt -s extglob
. (Apart usingsed
), you can avoid this, via the more complex:Test config file
Test code
Results
Result
Since your config file is a valid shell script, you can source it into your current shell:
Slightly DRYer, but trickier
awk -F\= '{gsub(/"/,"",$2);print "Content of " $1 " is " $2}' <filename>
Just FYI, another pure bash solution
I do in this way