cat
SH-2002Consider using cmd < file | ..
or cmd file | ..
instead. cat
is a tool for con"cat"enating files. Reading a single file as input to a program is considered a Useless Use Of Cat (UUOC).
pgrep
instead of grepping ps
output SH-2009If you are just after a pid
from a running program, then pgrep
is a much safer alternative. Especially if you are also looking for a pid
belonging to a certain user or group. pgrep
rolls a number of functionalities into one and can eliminate multiple greps
, cuts
, seds
and awks
.
Rather than adding >> something
after every single line, you can simply group the relevant commands and redirect the group. Now the file has to be opened and closed only once, which can be a performance gain.
grep -q
SH-2143grep -q
is a more performant way to indicate the existence of one or more matches for a pattern.
${variable//search/replace}
SH-2001Consider using parameter expansion to search and replace data. In the problematic code
the value is passed to sed
to do this, but for simple substitutions, parameter expansion can do it with less overhead.