shell script to read values from one file and replace it in other file
<p>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. </p>

<p><strong>file1.json</strong></p>

<pre><code>{
    "colorsArray":[{
            "red":"$ALERT_LEVEL",
            "green":"$NORMAL_LEVEL",
            "blue":"$RELAX_LEVEL"
        }
    ]
}
</code></pre>

<p><strong>file1.config</strong></p>

<pre><code>[root@ip10]# cat file1.config
ALERT_LEVEL=DANGER
NORMAL_LEVEL=NORMAL
RELAX_LEVEL=RELAX
</code></pre>

<p><strong>run.sh</strong></p>

<pre><code>    #!/bin/bash
set -x
if [ $# -ne 3 ]; then
  echo "USAGE:
        ./$0 file1.json file2.json file1.config"
  exit 1
fi
echo "#!/bin/bash
cat &gt; $2 &lt;&lt; EOF
`cat $1`
EOF" &gt; $2;
chmod +x $2;
# load variables into env
. $3
# actually replace variables
./$2
</code></pre>

<p><strong>Error:</strong> </p>

<pre><code>[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')
</code></pre>

<p><strong>file2.json</strong> appears, but it has no values replaced. </p>

<pre><code>root@ip10]# cat file2.json 
    {
        "colorsArray":[{
                "red":"",
                "green":"",
                "blue":""
            }
        ]
    }
</code></pre>