You need to either quote the entire awk
script, or escape the dollar signs so that the shell does not expand them as positional parameters before awk
is called. (Adding single quotes takes care of the other problem, which is that without a line continuation character, the awk
command itself ends at the end of the line and the rest of the script is parsed as incorrect bash
code):
awk -v start=$(head -n 1 ${i}) -v end=$(tail -n 1 ${i}) '
BEGIN {
...
'