mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2216 (markdown)
12
SC2216.md
12
SC2216.md
@@ -1,20 +1,24 @@
|
||||
## Piping to 'echo', a command that doesn't read stdin. Wrong command or missing xargs?
|
||||
## Piping to 'rm', a command that doesn't read stdin. Wrong command or missing xargs?
|
||||
|
||||
### Problematic code:
|
||||
|
||||
```sh
|
||||
find . -type f | echo "Results: "
|
||||
ls | echo # Want to print result
|
||||
cat files | rm # Want to delete items from a file
|
||||
find . -type f | xargs cp dir # Want to process 'find' output
|
||||
```
|
||||
|
||||
### Correct code:
|
||||
|
||||
```sh
|
||||
find . -type f -print0 | xargs -0 echo "Results: "
|
||||
ls
|
||||
cat files | while IFS= read -r file; do rm -- "$file"; done
|
||||
find . -type f -exec cp {} dir \;
|
||||
```
|
||||
|
||||
### Rationale:
|
||||
|
||||
You are redirecting to one of several commands that don't read from stdin.
|
||||
You are piping to one of several commands that don't read from stdin.
|
||||
|
||||
This may happen when:
|
||||
|
||||
|
Reference in New Issue
Block a user