Some bits of grep usage are where I disagree with Shellcheck
I have come to very much like shellcheck and now automatically use it on any shell script I'm writing or revising (at least any scripts for work; personal ones I'm sometimes lazier with). Although some of its issues are a little bit picky, using it is good for me so I go along with them. Well, with one exception, because I cannot go along with Shellcheck's views on using egrep and fgrep.
egrep is non-standard and deprecated. Use grep -E instead. fgrep is non-standard and deprecated. Use grep -F instead.
Sorry, nope. Both
fgrep are long standing programs
and names for these versions of
grep, and they will be present
on any sane Unix until the end of time (and I don't mean 2038, the
end of the 32-bit Unix epoch). I have a visceral and probably
irrational reaction to the idea of using the POSIXism of 'grep -E'
and 'grep -F' for them, and I have no intention of switching my
scripts away from using fgrep and egrep.
(And grep already has enough flags to keep track of, including important ones for searching test files in GNU Grep.)
Fortunately modern versions of Shellcheck (including the one in Ubuntu 18.04) can disable these warnings for your entire script, as covered in the wiki's page on ignoring errors. Just put a line in the comment at the start of your script to turn them off:
#!/bin/sh [...] # Disable warnings about use of egrep and fgrep # shellcheck disable=SC2196,SC2197
(I don't want to use a
$HOME/.shellcheckrc for this, because
I want our scripts to Shellcheck cleanly regardless of who runs
Comments on this page:Written on 17 April 2020.