diff --git a/SC2033.md b/SC2033.md new file mode 100644 index 0000000..fd881ec --- /dev/null +++ b/SC2033.md @@ -0,0 +1,20 @@ +# Shell functions can't be passed to external commands. + +### Problematic code: + + foo() { rm /run/foo; bar --baz; }; + sudo foo + +### Correct code: + + sudo sh -c 'rm /run/foo; bar --baz;' + +### Rationale: + +Shell functions are only known to the shell. External commands like `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. + +### Contraindications + +None. \ No newline at end of file