mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-03-12 12:35:25 -07:00
Updated SC2216 (markdown)
parent
3036bd8f85
commit
a436bef6e9
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:
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user