From 55f3a67941caac78dbdbd7b324e3d5503b1a2672 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Mon, 7 Sep 2020 20:50:37 -0700 Subject: [PATCH] Created SC3043 (markdown) --- SC3043.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 SC3043.md diff --git a/SC3043.md b/SC3043.md new file mode 100644 index 0000000..6882915 --- /dev/null +++ b/SC3043.md @@ -0,0 +1,33 @@ +## In POSIX sh, `local` is undefined. + +### Problematic code: + +```sh +myfunc() { + local i=0 + .. +} +``` + +### Correct code: + +In POSIX sh, you can adopt some convention to avoid accidentally overwriting variables names, e.g. prefixing with the function name: + +```sh +myfunc() { + _myfunc_i=0 + .. +} +``` + +### Rationale: + +`local` is supported in many shells, including bash, ksh, dash, and BusyBox ash. However, strictly speaking, it's not POSIX. + +### Exceptions: + +Since quite a lot of real world shells support this feature, you may decide to [[ignore]] the warning. + +### Related resources: + +* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!