From ab804213eac4cbc461bf1e26423680795a40ea5d Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Fri, 9 Mar 2018 11:45:49 -0800 Subject: [PATCH] Updated SC2216 (markdown) --- SC2216.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/SC2216.md b/SC2216.md index 7369dee..d309a19 100644 --- a/SC2216.md +++ b/SC2216.md @@ -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.