mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2217 (markdown)
33
SC2217.md
Normal file
33
SC2217.md
Normal file
@@ -0,0 +1,33 @@
|
||||
## Redirecting to 'echo', a command that doesn't read stdin. Bad quoting or missing xargs?
|
||||
|
||||
### Problematic code:
|
||||
|
||||
```sh
|
||||
echo << eof
|
||||
Hello World
|
||||
eof
|
||||
```
|
||||
|
||||
### Correct code:
|
||||
|
||||
```sh
|
||||
cat << eof
|
||||
Hello World
|
||||
eof
|
||||
```
|
||||
|
||||
### 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 quoting angle brackets, e.g. using `echo <p>Hello` which tries to read from a file `p`.
|
||||
* Missing `xargs`, e.g. `mv -t dir < files` instead of `xargs mv -t dir < files` (or more safely, `tr '\n' '\0' < files | xargs -0 mv -t dir`), because stdin should be passed as parameters.
|
||||
|
||||
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