mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2216 (markdown)
@@ -5,7 +5,8 @@
|
|||||||
```sh
|
```sh
|
||||||
ls | echo # Want to print result
|
ls | echo # Want to print result
|
||||||
cat files | rm # Want to delete items from a file
|
cat files | rm # Want to delete items from a file
|
||||||
find . -type f | xargs cp dir # Want to process 'find' output
|
find . -type f | cp dir # Want to process 'find' output
|
||||||
|
rm file | true # Want to ignore errors
|
||||||
```
|
```
|
||||||
|
|
||||||
### Correct code:
|
### Correct code:
|
||||||
@@ -14,6 +15,7 @@ find . -type f | xargs cp dir # Want to process 'find' output
|
|||||||
ls
|
ls
|
||||||
cat files | while IFS= read -r file; do rm -- "$file"; done
|
cat files | while IFS= read -r file; do rm -- "$file"; done
|
||||||
find . -type f -exec cp {} dir \;
|
find . -type f -exec cp {} dir \;
|
||||||
|
rm file || true
|
||||||
```
|
```
|
||||||
|
|
||||||
### Rationale:
|
### Rationale:
|
||||||
@@ -25,6 +27,7 @@ This may happen when:
|
|||||||
* Confusing one command for another, e.g. using `echo` where `cat` was intended.
|
* Confusing one command for another, e.g. using `echo` where `cat` was intended.
|
||||||
* Incorrectly refactoring, leaving a `|` on the previous line.
|
* 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).
|
* Missing `xargs`, because stdin should be passed as positional parameters instead (use `xargs -0` if at all possible).
|
||||||
|
* Intending to use `||` instead of `|`
|
||||||
|
|
||||||
Check your logic, and rewrite the command so data is passed correctly.
|
Check your logic, and rewrite the command so data is passed correctly.
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user