mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-04 11:49:42 +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:
|
### Problematic code:
|
||||||
|
|
||||||
```sh
|
```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:
|
### Correct code:
|
||||||
|
|
||||||
```sh
|
```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:
|
### 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:
|
This may happen when:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user