mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Add advice for multiple files - https://github.com/koalaman/shellcheck/issues/1920
14
SC2126.md
14
SC2126.md
@@ -12,6 +12,20 @@ grep foo | wc -l
|
||||
grep -c foo
|
||||
```
|
||||
|
||||
#### For multiple files
|
||||
|
||||
Instead of:
|
||||
|
||||
```sh
|
||||
grep foo *.log | wc -l
|
||||
```
|
||||
|
||||
Pipe all the file contents into `grep` (passing the files directly to `grep` causes `-c` to print each file's count separately, rather than the total):
|
||||
|
||||
```sh
|
||||
cat *.log | grep foo -c
|
||||
```
|
||||
|
||||
### Rationale:
|
||||
|
||||
This is purely a stylistic issue. `grep` can count lines without piping to `wc`.
|
||||
|
Reference in New Issue
Block a user