Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ALIAS: unbound variable #1526

Closed
alexjurkiewicz opened this issue May 17, 2017 · 7 comments
Closed

ALIAS: unbound variable #1526

alexjurkiewicz opened this issue May 17, 2017 · 7 comments
Labels
bugs Oh no, something's broken :-(

Comments

@alexjurkiewicz
Copy link

alexjurkiewicz commented May 17, 2017

  • 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

@alexjurkiewicz
Copy link
Author

Related issue: #1505

@ljharb
Copy link
Member

ljharb commented May 17, 2017

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

@ljharb
Copy link
Member

ljharb commented May 17, 2017

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

@alexjurkiewicz
Copy link
Author

alexjurkiewicz commented May 17, 2017

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

@ljharb
Copy link
Member

ljharb commented May 17, 2017

Thanks, turns out it's a simple fix.

@alexjurkiewicz
Copy link
Author

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

@ljharb ljharb added the bugs Oh no, something's broken :-( label May 17, 2017
@ljharb ljharb closed this as completed in 4f626ea May 17, 2017
@alexjurkiewicz
Copy link
Author

👍 thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugs Oh no, something's broken :-(
Projects
None yet
Development

No branches or pull requests

2 participants