mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-03-12 12:35:25 -07:00
Created SC3043 (markdown)
parent
17f4409202
commit
55f3a67941
33
SC3043.md
Normal file
33
SC3043.md
Normal file
@ -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!
|
Loading…
x
Reference in New Issue
Block a user