nvm
nvm copied to clipboard
`ksh` doesn't support `local`
ksh
doesn't support local
with portable function syntax, and dash
doesn't support typeset
.
zsh
does have the typeset
builtin, and it seems to work as expected (zsh 5.0.5 (x86_64-apple-darwin14.0)
):
zsh -c 'foo() { typeset x=1; echo $x; }; foo; echo ${x-no global x}'
Is there a particular aspect that's not working?
Hm, I typed that from memory. There was a reason we can't use typeset
- maybe dash
doesn't have it? I'll have to investigate.
Good point: dash
has local
(which is non-POSIX), but not typeset
.
Conversely, ksh
has typeset
, but not local
.
An added ksh
gotcha is that typeset
only creates local variables when using the NON-POSIX function foo { … }
syntax.
Good to know, thanks! I've updated the issue description.
If it weren't for the variable-scope issue, you could make ksh
happy with this trick:
[ -n "$KSH_VERSION" ] && alias local='typeset'
foo() {
local x=2
echo "$x"
}
foo
echo ${x-no global x}
But, as you'll see, $x
became global, because I've used the POSIX function-declaration style (foo() { ... }
).
Using function foo {...}
syntax would result in local variables, wouldn't work in dash
(but does work in zsh
and bash
).
Sadly, there appears to be no configuration item that tells ksh
to create local variables with typeset
- it appears to be solely controlled by the function-declaration style.
So is support for ksh ever going to be a thing?
@jlvivero nvm already should work on ksh; it just creates a lot of global variables due to lack of local
.
What I'm looking for is some ergonomic, hard-to-mess-up way to detect and support both local
and typeset
as needed.
it's just that when I install nvm with ksh(no option of changing this). I get a LOT of local not found messages. And maybe I'm doing something wrong, but basically if I add export NVM_DIR .... lines to .kshrc whenever I do nvm ls-remote I get more of those messages and /bin/sort as a result
That's why I thought this issue was about support for ksh
Specifically the issue is about how to avoid those warnings :-) nvm should work fine, you'll just be swamped with the warnings, which isn't what i'd call "support".
In order to get portable local variables, they need to be unset
before returning or existing from a function.
It should not take too long todo, I'm happy to help if the need is still there?
@merlindiavova yes, that would be amazing - please uncomment ksh tests in that PR as well :-)
Will make start today