mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2216 (markdown)
29
SC2216.md
Normal file
29
SC2216.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
## Piping to 'echo', a command that doesn't read stdin. Wrong command or missing xargs?
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
find . -type f | echo "Results: "
|
||||||
|
```
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
find . -type f -print0 | xargs -0 echo "Results: "
|
||||||
|
```
|
||||||
|
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
You are redirecting to one of several commands that don't read from stdin.
|
||||||
|
|
||||||
|
This may happen when:
|
||||||
|
|
||||||
|
* Confusing one command for another, e.g. using `echo` where `cat` was intended.
|
||||||
|
* Incorrectly refactoring, leaving a `|` on the previous line.
|
||||||
|
* Missing `xargs`, because stdin should be passed as positional parameters instead (use `xargs -0` if at all possible).
|
||||||
|
|
||||||
|
Check your logic, and rewrite the command so data is passed correctly.
|
||||||
|
|
||||||
|
### Exceptions:
|
||||||
|
|
||||||
|
If you've overridden a command to return output, you can either rename it to make this obvious, or [[ignore]] this message.
|
Reference in New Issue
Block a user