Nvm: ALIAS: unbound variable

Created on 17 May 2017  路  7Comments  路  Source: nvm-sh/nvm

  • Operating system and version: ubuntu 16.04 LTS

With nvm 0.33.2 (and presumably trunk, the same code exists), I see the following error occasionally when using nvm inside a script with set -eu specified:

<snip>/.nvm/nvm.sh: line 3103: ALIAS: unbound variable

Command run: nvm ls 6

bugs

All 7 comments

Related issue: #1505

hmm, the code you linked to has the variable set here, which should mean it's always bound.

although I can repro it locally, so i'll figure it out shortly :-)

The issue is this snippet:

        if [ "${ALIAS-}" = '--' ]; then
          unset ALIAS
        fi

        nvm_list_aliases "${ALIAS}"

The unset line is (in some cases, I don't understand nvm well enough to know when the condition fires) removing the variable. A smaller test case:

$ cat test.sh
#!/bin/bash -u
a="3"
echo $a
unset a
echo $a
$ ./test.sh
3
./test.sh: line 5: a: unbound variable

Thanks, turns out it's a simple fix.

Looking at the code in nvm_list_aliases, you can probably replace unset ALIAS with ALIAS=""...? That function looks defensively written :)

馃憤 thanks!

Was this page helpful?
0 / 5 - 0 ratings