From 3ef17ed81d5cdaa8bc6e24002c685edb0900d228 Mon Sep 17 00:00:00 2001 From: koalaman Date: Tue, 25 Feb 2014 17:20:58 -0800 Subject: [PATCH] Updated SC2033 (markdown) --- SC2033.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SC2033.md b/SC2033.md index 2ab0fc1..80abcfd 100644 --- a/SC2033.md +++ b/SC2033.md @@ -3,15 +3,15 @@ ### Problematic code: foo() { bar --baz "$@"; frob --baz "$@"; }; - find . -print0 | xargs -0 foo + find . -exec foo {} + ### Correct code: - find . -print0 | xargs -0 sh -c 'bar --baz "$@"; frob --baz "$@";' -- + find . -exec sh -c 'bar --baz "$@"; frob --baz "$@";' -- {} + ### Rationale: -Shell functions are only known to the shell. External commands like `xargs`, `su` and `sudo` do not recognize shell functions. +Shell functions are only known to the shell. External commands like `find`, `xargs`, `su` and `sudo` do not recognize shell functions. Instead, the function contents can be executed in a shell, either through `sh -c` or by creating a separate shell script as an executable file.