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