Provide a custom grep() function to catch direct usage of the command. Bare grep calls are generally incompatible with pipefail and errexit behavior (where a failed match causes the script to exit). Developers can still call grep via command grep if that behavior is explicitly desired.
Showing the changes to scripts/livepatch (1 of 1 file). Show all
Unified · Split
| @@ -56,6 +56,13 @@ grep0() { · 55 unmodified lines | ||
| 56 | 56 | command grep "$@" || true |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | +# Because pipefail is enabled, the grep0 helper should be used instead of | |
| 60 | +# grep, otherwise a failed match can propagate to an error. | |
| 61 | +grep() { | |
| 62 | + echo "error: $SCRIPT: use grep0 or 'command grep' instead of bare grep" >&2 | |
| 63 | + exit 1 | |
| 64 | +} | |
| 65 | + | |
| 59 | 66 | status() { |
| 60 | 67 | echo "$*" |
| 61 | 68 | } |