3 ms·
You can do it in compound commands as well: while read -r LINE do printf %s "$LINE" done <<FOO foo bar baz FOO This is faster than using cat (one less p
by alganet 4y ago
You can do it in compound commands as well:
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).