I would like to replace a set of strings into a new file. Source file file1.json values has to be replaced by values from file1.config into file file2.json. I have following script that is failing to do so.
file1.json
{
"colorsArray":[{
"red":"$ALERT_LEVEL",
"green":"$NORMAL_LEVEL",
"blue":"$RELAX_LEVEL"
}
]
}
file1.config
[root@ip10]# cat file1.config
ALERT_LEVEL=DANGER
NORMAL_LEVEL=NORMAL
RELAX_LEVEL=RELAX
run.sh
#!/bin/bash
set -x
if [ $# -ne 3 ]; then
echo "USAGE:
./$0 file1.json file2.json file1.config"
exit 1
fi
echo "#!/bin/bash
cat > $2 << EOF
`cat $1`
EOF" > $2;
chmod +x $2;
# load variables into env
. $3
# actually replace variables
./$2
Error:
[root@ip10]# ./run2.sh file1.json file2.json file1.config
./file2.json: line 11: warning: here-document at line 2 delimited by end-of-file (wanted `EOF')
file2.json appears, but it has no values replaced.
root@ip10]# cat file2.json
{
"colorsArray":[{
"red":"",
"green":"",
"blue":""
}
]
}