I am trying to generate a perl script and run it from a bash script, but I am running into issues:
#!/bin/bash
str="perl"
array=( one two three )
for i in "${array[@]}"
do
str=$str" -e 'print \"$i \";'"
done
echo "$str"
echo "AND THE PERL OUTPUT: "
$str
generates the output:
perl -e 'print "one ";' -e 'print "two ";' -e 'print "three ";'
AND THE PERL OUTPUT:
Can't find string terminator "'" anywhere before EOF at -e line 1.
When I run the generated perl command perl -e 'print "one ";' -e 'print "two ";' -e 'print "three ";' manually, it works, but when I try to run it from the bash script, I get Can't find string terminator "'" anywhere before EOF at -e line 1.
Cannot seem to figure out where I am missing the terminator
set -xto see exactly what's being executedexec -c perl -e ''\''print' '"one' '";'\''' -e ''\''print' '"two' '";'\''' -e ''\''print' '"three' '";'\'''