mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Revert 55f3a67941caac78dbdbd7b324e3d5503b1a2672...40f5ce0eee45f4ecc27232d838e0cb05383708f7 on SC3043
26
SC3043.md
26
SC3043.md
@@ -20,29 +20,6 @@ myfunc() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also `unset` the variable at the end of the function:<sup><a href="#related-resources">1</a></sup>
|
|
||||||
|
|
||||||
```sh
|
|
||||||
myfunc() {
|
|
||||||
i=0
|
|
||||||
..
|
|
||||||
unset i
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
You can also use POSIX’s `set +a` or `set +o allexport` which prevents the
|
|
||||||
“export attribute” from being “set for each variable to which an
|
|
||||||
assignment is performed”:<sup><a href="#related-resources">2</a></sup>
|
|
||||||
|
|
||||||
```sh
|
|
||||||
myfunc() {
|
|
||||||
set +a || set +o allexport # either will work – don’t use both.
|
|
||||||
i=0
|
|
||||||
..
|
|
||||||
set -a || set -o allexport # optionally undo `set` modifications
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Rationale:
|
### Rationale:
|
||||||
|
|
||||||
`local` is supported in many shells, including bash, ksh, dash, and BusyBox ash. However, strictly speaking, it's not POSIX.
|
`local` is supported in many shells, including bash, ksh, dash, and BusyBox ash. However, strictly speaking, it's not POSIX.
|
||||||
@@ -52,8 +29,5 @@ myfunc() {
|
|||||||
Since quite a lot of real world shells support this feature, you may decide to [[ignore]] the warning.
|
Since quite a lot of real world shells support this feature, you may decide to [[ignore]] the warning.
|
||||||
|
|
||||||
### Related resources:
|
### Related resources:
|
||||||
1. [Shell Command Language § `unset`](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#unset) ([archived](https://web.archive.org/web/20180326004734/https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#unset))
|
|
||||||
2. [Shell Command Language § Description](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_25_03) ([archived](https://web.archive.org/web/20180326004734/https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_25_03))
|
|
||||||
|
|
||||||
|
|
||||||
* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!
|
* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!
|
||||||
|
Reference in New Issue
Block a user