mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2033 (markdown)
@@ -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.
|
||||
|
||||
|
Reference in New Issue
Block a user