The very first example (echo "Hello $NAME!") won’t work if `histexpand` is set, which I believe is the default.
Maybe they meant `cat file.txt | while ...`? Even then, you never want to do that when you're reading because elements of a pipeline are run in subshells. The usual idiom is:
while cond; do
thing
done < input > output
It's also the problem with cheatsheets: the underlying idea in bash is that compound statements are like mini programs, so they have file handles that can be redirected. That doesn't come through a cheatsheet very well. If enabled, history expansion will be performed
unless an ! appearing in double quotes is escaped
using a backslash. Only backslash (\) and single quotes can quote the history expansion character.
where the newer man page says: Only backslash (\) and single quotes can quote the history expansion character,
but the history expansion character is also treated as quoted if it
immediately precedes the closing double quote in a double-quoted string.
Thanks for pointing this out!