Heredocs cannot be indented like the rest of the script (unless you use -EOM
but then you can only indent with tabs). After all, the purpose of the heredoc is to allow you to write something that will appear as is. This means that the EOM
cannot be like this:
while something;
do
command <<EOM
Hello!
EOM
done
Instead, the EOM
(or any other marked you use) needs to be the only thing on the line, so no whitespace or anything else before or after it. Like this:
while something;
do
command <<EOM
Hello!
EOM
done
Also, note that because of the reasons mentioned above, the leading whitespace will also be included, so that this:
c=0;
while [ $c -eq 0 ];
do
cat <<EOM
Hello!
EOM
let c++
done
Would print:
$ foo.sh
Hello!
While this:
c=0;
while [ $c -eq 0 ];
do
cat <<EOM
Hello!
EOM
let c++
done
Would print:
$ foo.sh
Hello!
Finally, when running your script, I get a different error:
$ foo.sh
I am currently in the following directory:
/home/terdon/foo
/home/terdon/scripts/foo.sh: line 108: warning: here-document at line 84 delimited by end-of-file (wanted `EOM')
/home/terdon/scripts/foo.sh: line 109: syntax error: unexpected end of file
This will be because I am not giving the same input data and, since you were not ending the EOM correctly, your data was probably being processed by the script and that's why you saw a different error. I expect my fix will get rid of it though, as it let me run your script through to the end on my machine.