nvm: nvm install crashes bash script when bash is set to exit on error
-
Operating system and version: OSX 10.11.6
-
How did you install
nvm
? (e.g. install script in readme, Homebrew): curl -
What steps did you perform?
I ran this script:
Marks-MacBook-Pro:tmp marksmith$ cat /tmp/nvm_exit_on_error_issue.sh
#!/usr/bin/env bash
set -e; set -o pipefail
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
nvm install stable
echo "done"
exit 0
- What happened?
Marks-MacBook-Pro:tmp marksmith$ /tmp/nvm_exit_on_error_issue.sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 13226 100 13226 0 0 3637 0 0:00:03 0:00:03 --:--:-- 3637
=> Downloading nvm from git to '/Users/marksmith/.nvm'
=> Cloning into '/Users/marksmith/.nvm'...
remote: Enumerating objects: 278, done.
remote: Counting objects: 100% (278/278), done.
remote: Compressing objects: 100% (249/249), done.
remote: Total 278 (delta 33), reused 88 (delta 16), pack-reused 0
Receiving objects: 100% (278/278), 142.36 KiB | 65.00 KiB/s, done.
Resolving deltas: 100% (33/33), done.
=> Compressing and cleaning up git repository
=> nvm source string already in /Users/marksmith/.bash_profile
=> bash_completion source string already in /Users/marksmith/.bash_profile
=> Close and reopen your terminal to start using nvm or run the following to use it now:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
The script doesn’t complete.
Now comment out the exit on error line and run again:
Marks-MacBook-Pro:tmp marksmith$ vim /tmp/nvm_exit_on_error_issue.sh
Marks-MacBook-Pro:tmp marksmith$ cat /tmp/nvm_exit_on_error_issue.sh | grep pipe
#set -e; set -o pipefail
Marks-MacBook-Pro:tmp marksmith$ unset NVM_DIR; rm -rf ~/.nvm
Marks-MacBook-Pro:tmp marksmith$ /tmp/nvm_exit_on_error_issue.sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 13226 100 13226 0 0 5546 0 0:00:02 0:00:02 --:--:-- 5545
=> Downloading nvm from git to '/Users/marksmith/.nvm'
=> Cloning into '/Users/marksmith/.nvm'...
remote: Enumerating objects: 278, done.
remote: Counting objects: 100% (278/278), done.
remote: Compressing objects: 100% (249/249), done.
remote: Total 278 (delta 33), reused 88 (delta 16), pack-reused 0
Receiving objects: 100% (278/278), 142.36 KiB | 68.00 KiB/s, done.
Resolving deltas: 100% (33/33), done.
=> Compressing and cleaning up git repository
=> nvm source string already in /Users/marksmith/.bash_profile
=> bash_completion source string already in /Users/marksmith/.bash_profile
=> Close and reopen your terminal to start using nvm or run the following to use it now:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
Downloading and installing node v12.7.0...
Downloading https://nodejs.org/dist/v12.7.0/node-v12.7.0-darwin-x64.tar.gz...
######################################################################## 100.0%
Computing checksum with shasum -a 256
Checksums matched!
Creating default alias: default -> stable (-> v12.7.0)
done
The script completes.
- What did you expect to happen?
The script to complete in both cases.
- Is there anything in any of your profile files (
.bashrc
,.bash_profile
,.zshrc
, etc) that modifies thePATH
?
Only .bash_profile has the nvm loading code from the installation guide.
About this issue
- Original URL
- State: open
- Created 5 years ago
- Comments: 20 (10 by maintainers)
Oh my days, what a can of worms, thanks for the link.
hmm, that suggests it’s failing on an
nvm_echo
which is just a wrappedprintf
. That doesn’t make much sense.