From 0d9ab87a68101eeecd5343bfab2f454ade531205 Mon Sep 17 00:00:00 2001 From: koalaman Date: Sat, 10 Oct 2015 21:05:34 -0700 Subject: [PATCH] Created SC2168 (markdown) --- SC2168.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 SC2168.md diff --git a/SC2168.md b/SC2168.md new file mode 100644 index 0000000..84e9fd0 --- /dev/null +++ b/SC2168.md @@ -0,0 +1,22 @@ +## 'local' is only valid in functions. + +### Problematic code: + +```sh +local foo=bar +echo "$foo" +``` + +### Correct code: + +```sh +foo=bar +echo "$foo" +``` +### Rationale: + +In Bash, `local` can only be used in functions. In other contexts, it's an error. + +### Exceptions: + +It's possible to source files containing `local` from a function context but not from any other context. This is not good practice, but in these cases you can [[ignore]] this error. \ No newline at end of file