From 3036bd8f85e4e928235ed754dda09a4b64139e9e Mon Sep 17 00:00:00 2001 From: koalaman Date: Mon, 3 Jul 2017 15:58:41 -0700 Subject: [PATCH] Created SC2216 (markdown) --- SC2216.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 SC2216.md diff --git a/SC2216.md b/SC2216.md new file mode 100644 index 0000000..51dec94 --- /dev/null +++ b/SC2216.md @@ -0,0 +1,29 @@ +## Piping to 'echo', a command that doesn't read stdin. Wrong command or missing xargs? + +### Problematic code: + +```sh +find . -type f | echo "Results: " +``` + +### Correct code: + +```sh +find . -type f -print0 | xargs -0 echo "Results: " +``` + +### Rationale: + +You are redirecting to one of several commands that don't read from stdin. + +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). + +Check your logic, and rewrite the command so data is passed correctly. + +### Exceptions: + +If you've overridden a command to return output, you can either rename it to make this obvious, or [[ignore]] this message. \ No newline at end of file