From a436bef6e9ba9cea5e9f723d2da860ef9a816afb Mon Sep 17 00:00:00 2001 From: koalaman Date: Mon, 3 Jul 2017 16:02:37 -0700 Subject: [PATCH] Updated SC2216 (markdown) --- SC2216.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/SC2216.md b/SC2216.md index 51dec94..7369dee 100644 --- a/SC2216.md +++ b/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: