<<EOF (expands variables etc)
<<'EOF' (doesn't expand variables etc)
<<-EOF (trims leading tabs)
Am I missing any more of the tricks?
<<EOF (expands variables etc)
<<'EOF' (doesn't expand variables etc)
<<-EOF (trims leading tabs)
Am I missing any more of the tricks?
while read -r LINE
do printf %s "$LINE"
done <<FOO
foo
bar
baz
FOO
This is faster than using cat (one less path lookup, one less fork, one less exec, read is builtin), works on all shells.
There is a <<-'EOF' as well (trims left tabs and does not expand vars).
Another cool trick that only bash and zsh have is `printf -v NAME`, which prints to a variable instead of stdout. You can use it to avoid subshells (one less fork for each subshell avoided).
sed 's/^ *//' <<EOF
Which I'd prefer anyways because it's less cryptic. I try to stay away from the obscure, rarely used notations because I'll always have to look it up in StackOverflow anytime I come back to it. These can be confusingly sharp edges.