koalaman / shellcheck Public
SC2129
Joachim Ansorg edited this page Nov 12, 2021
·
6 revisions
Consider using { cmd1; cmd2; } >> file instead of individual redirects.
Problematic code:
echo foo >> file
date >> file
cat stuff >> file
Correct code:
{
echo foo
date
cat stuff
} >> fileRationale:
Rather than adding >> something after every single line, you can simply group the relevant commands and redirect the group. So the file has to be opened and closed only once and it means a performance gain.
Exceptions:
This is mainly a stylistic issue, and can freely be ignored.