4 ms·
FYI, using `local foo=$(some-command)` does not actually make the variable local. main() { local count=$(git rev-list --count HEAD) echo $count
by emptysea 7y ago
FYI, using `local foo=$(some-command)` does not actually make the variable local.
main() {
local count=$(git rev-list --count HEAD)
echo $count
foo
}
foo() {
echo $count
}
main
prints:
2282
2282
- minitech 7y agoSure it does, that’s just how locals work (in bash and similar). Try printing it after `main` with and then without `local`.
- emptysea 7y agoAh my mistake Anyways there are some more subtle caveats discussed in this blogpost I was trying to remember: https://jmmv.dev/2018/03/shell-readability-local.html https://jmmv.dev/2018/03/shell-readability-local.html