Hi, short overview is that set -u in a script is letting my nvm install --lts fail, due obvious reasons.
A quick response would is super welcomed.
#!/bin/sh
setup_nvm() {
export NVM_DIR="$(mktemp -d /tmp/nvm-XXXXXXXX)"
[ -d "${NVM_DIR}" ]
git clone --depth=10 https://github.com/creationix/nvm.git "${NVM_DIR}"
cd "${NVM_DIR}"
git checkout $(git describe --abbrev=0 --tags --match "v[0-9]*" origin)
. "${NVM_DIR}/nvm.sh"
nvm install --lts
echo "${NVM_DIR}"
}
setup_nvm # works
set -u
setup_nvm # fails
I get the error message: NVM_LS_REMOTE_IOJS_OUTPUT: parameter not set.
This happens, because I'm using set -u in my script. I'd like to have a very quick conversation regards how we should resolve the issue:
set +u; setup_nvm; set -u in my script)set -eu enabled by default inside nvm?~NVM_LS_REMOTE_IOJS_OUTPUT is assigned outside the condition above. https://github.com/creationix/nvm/blob/master/nvm.sh#L525The first option is the proper workaround; setting shell options is hostile to other things that run in the same shell. The second option isn鈥檛 an option.
The third option, however, is a fine longer-term fix. Thanks!
There your pull-request goes. If it's alright, I've also added set -u to your test case for lts.
I could also do local foo=, but I'm not sure if that is part of your practices.
In tests, we don't worry about local; in actual code, we always do:
local foo
foo=1
to account for ksh.
Great :-), then feel free to merge #1665 at some point. Wish you a great weekend!
Closed in #1665.
Hi @norpol , I wondered how your script works, you are sourcing and installing node inside a script. But the parent shell does not have node installed.
The node and npm still not found in command line.
I'm trying to automate the nvm installation, but got stuck here.
This is the script I tried to run
#!/bin/bash
setup_nvm() {
export NVM_DIR="${HOME}/.nvm"
export NODE_VERSION=6.11.5
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh | bash
. "${NVM_DIR}/nvm.sh"
nvm list
nvm install ${NODE_VERSION}
nvm use ${NODE_VERSION}
nvm alias default ${NODE_VERSION}
npm install -g grunt
}
setup_nvm
I can see them installed correctly. But when I type node, it says command not found
@liqiang372 You have to re-source nvm.sh in your parent shell after doing that, if you're doing that in a script.
Also, you don't need the nvm use command, or the nvm alias default command if it's the first node version you're installing.
@ljharb got it, thanks! So there is no ultimate automation of this installation. I have to at last run
$ . ~/.nvm/nvm.sh
by myself to make current shell aware of the change
Yes, that's correct.
Most helpful comment
Yes, that's correct.