Updated SC2216 (markdown)

Vidar Holen
2018-03-09 11:45:49 -08:00
parent 74569a5b44
commit ab804213ea

@@ -5,7 +5,8 @@
```sh
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
find . -type f | cp dir # Want to process 'find' output
rm file | true # Want to ignore errors
```
### Correct code:
@@ -14,6 +15,7 @@ find . -type f | xargs cp dir # Want to process 'find' output
ls
cat files | while IFS= read -r file; do rm -- "$file"; done
find . -type f -exec cp {} dir \;
rm file || true
```
### Rationale:
@@ -25,6 +27,7 @@ This may happen when:
* Confusing one command for another, e.g. using `echo` where `cat` was intended.
* 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).
* Intending to use `||` instead of `|`
Check your logic, and rewrite the command so data is passed correctly.