Hi all,
Thought I had an understanding of this, guess I'm wrong.......
Problem is this: I have an input file, db.conf, looking like this (shortened):
Code:
# start db config file
# tets01
dbname=tets01
dm="Some Bloke"
tak="o=left"
# dummy01
dbname=dummy01
dm="someuser"
tak="o=right"
# end db config file
I need to export dbname, dm and tak, based on the db given (tets01 or dummy01 in the above example).
The export part is giving me trouble, instead of exporting 3 variables it exports 1 (dbname), which holds all other entries.
The script (tailored for this question):
Code:
#!/bin/bash
# -------------------------------------------------------------------------- #
#set -x
DB="$1"
export dummy1=testing123 dummy2="123 testing"
for EXPORT_ME in "`awk -v DB="${DB}" \
'BEGIN { FS="\n" ; RS="" }
$1 ~ DB { print $2, $3, $4, $5 }
' db.conf`"
do
export "$EXPORT_ME"
done
echo "----------------------------------------------------------"
echo "dummy1 : $dummy1"
echo "dummy2 : $dummy2"
echo "----------------------------------------------------------"
echo "dbname : $dbname"
echo "dm : $dm"
echo "tak : $tak"
echo "----------------------------------------------------------"
# -------------------------------------------------------------------------- #
# end
Example run:
Code:
$ ./db.parser tets01
----------------------------------------------------------
dummy1 : testing123
dummy2 : 123 testing
----------------------------------------------------------
dbname : tets01 dm="Some Bloke" tak="o=left"
dm :
tak :
----------------------------------------------------------
$ ./db.parser dummy01
----------------------------------------------------------
dummy1 : testing123
dummy2 : 123 testing
----------------------------------------------------------
dbname : dummy01 dm="someuser" tak="o=right"
dm :
tak :
----------------------------------------------------------
I think this has to do with the
export "$EXPORT_ME" not expanding the content because of the double quotes. Loosing them is not an option 'cause the dm entry can have spaces (tak as well).
set -x shows this difference between the pasing of the dummy's and the parsing of EXPORT_ME:
dummy:
+ export dummy1=testing123 'dummy2=123 testing'
export_me:
+ export 'dbname=tets01 dm="Some Bloke" tak="o=left" '
Which says it all.
Anyway around this? db.conf file cannot change, all the rest is useless anyway so hack away
Thanks in advance.