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.