Revert 55f3a67941caac78dbdbd7b324e3d5503b1a2672...40f5ce0eee45f4ecc27232d838e0cb05383708f7 on SC3043

Emanuele Torre
2022-06-01 17:52:05 +02:00
parent 9aea9b7bea
commit ec2aa8a178

@@ -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 POSIXs `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 dont use both.
i=0
..
set -a || set -o allexport # optionally undo `set` modifications
}
```
### Rationale:
`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.
### 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!