Heredocs are tricky beasts to get better. If you use 'EOF' , what exactly should be the closing line, with no spaces in front, like yours.
Alternatively, you can use the <<- option, which removes all leading tab characters from the lines in the heredoc and the closing line according to the following decoding (where <tab> is the TAB character):
pax> cat <<-'eof' ...> 1 ...< 2 ...> <tab>eof ...> 4 ...> eof 1 2 <tab>eof 4 pax> cat <<-'eof' ...> 1 ...> 2 ...> <tab>eof 1 2
Using the <<- option allows you to use more accurate files, but this is not useful if you want, of course, to save the main tabs. From the bash manpage:
If the redirection operator is <<- , then all leading tab characters are removed from the input lines and the line containing the delimiter. This allows here-documents in shell scripts to be indented in a natural way.
Of course, if you just want to use these files as flag files, it is better to use cat with heredoc. Just use:
touch "$basedirectory$FEATURE_EXT.$SENT_EXT"
This will create the file if it does not exist, and update the modification time if it is like cat , but without chaos with heredocs. It will not empty the file, but if you need it for some reason:
rm -f "$basedirectory$FEATURE_EXT.$SENT_EXT" touch "$basedirectory$FEATURE_EXT.$SENT_EXT"
will do the trick.
However, since heredoc does display one blank line (single character \n ), you can choose to:
echo >"$basedirectory$FEATURE_EXT.$SENT_EXT"
instead.