Updated SC2033 (markdown)

koalaman
2014-02-25 17:20:58 -08:00
parent 31644a91cc
commit 3ef17ed81d

@@ -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.