If the here document should only be added if none of it is present, you can use grep:
cat <<-"EOF1" >>> myPath/myFile.append
content...
EOF1
if ! grep -F -q -f myPath/myFile{.append,}; then
cat myPath/myFile.append >> myPath/myFile
fi
To understand this, consider the following.
grep -F -q -f myPath/myFile{.append,}is expanded by the shell togrep -F -q -f myPath/myFile.append myPath/myFile.The
grepcommand searchesmyPath/myFile(the file to which the text should be added if necessary) for any fixed string (-F) contained inmyPath/myFile.append(the file containing the text to add), reading one pattern per line (-f), and indicates whether it finds any only by its exit code, with no output (-q).The result is then negated
!, so that theifblock’sthenpart is only run ifgrepdoesn’t find anything.