koalaman / shellcheck

ShellCheck, a static analysis tool for shell scripts
https://www.shellcheck.net
GNU General Public License v3.0
36.4k stars 1.78k forks source link

Suggest simpilifcation for grep -v pipeline #1219

Open bje- opened 6 years ago

bje- commented 6 years ago

For new checks and feature suggestions

Here's a snippet or screenshot that shows the problem:


#!/bin/bash

grep -v string1 FILE | grep -v string2 | grep -v string3 | grep -v string4 | grep -v string5

Here's what shellcheck currently says:

No issues detected.

Here's what I wanted or expected to see:

Shellcheck should suggest eliminating the long pipeline and replacing with a single command like grep -v -e string1 -e string2 -e string3 -e string4 -e string5.

Dmole commented 6 years ago

grep -vE "string[1-5]|etc"

would by my preference.

bje- commented 6 years ago

Sure, even better.

Nightfirecat commented 6 years ago

@Dmole Let's say, for the sake of argument, that the regexes are unique and distinct and cannot be compacted like that. grep -v -e foo -e bar -e baz

Dmole commented 6 years ago

grep -Ev "foo|bar|baz"