Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
These lines of commands work when run directly in Terminal, but fail when run as the contents of a file.
#!/bin/sh
# this test case script assumes that you are on macOS and have Homebrew (brew) installed
set -e
brew install nvm
mkdir -p ~/.nvm
export NVM_DIR="$HOME/.nvm"
source "/usr/local/opt/nvm/nvm.sh"
nvm install v6.10.3
nvm use --delete-prefix v6.10.3

When run as a script:

$ ./bootstrap.sh 
Warning: nvm 0.33.11 is already installed and up-to-date
To reinstall 0.33.11, run `brew reinstall nvm`
Downloading and installing node v6.10.3...
Downloading https://nodejs.org/dist/v6.10.3/node-v6.10.3-darwin-x64.tar.xz...
######################################################################## 100.0%
Binary download failed, trying source. 
$ 

When run from the prompt:

$ set -e
$ 
$ brew install nvm
Warning: nvm 0.33.11 is already installed and up-to-date
To reinstall 0.33.11, run `brew reinstall nvm`
$ 
$ mkdir -p ~/.nvm
$ export NVM_DIR="$HOME/.nvm"
$ source "/usr/local/opt/nvm/nvm.sh"
$ 
$ nvm install v6.10.3
Downloading and installing node v6.10.3...
Downloading https://nodejs.org/dist/v6.10.3/node-v6.10.3-darwin-x64.tar.xz...
######################################################################## 100.0%
Computing checksum with shasum -a 256
Checksums matched!
Creating default alias: default -> v6.10.3
$ nvm use --delete-prefix v6.10.3     
Now using node v6.10.3 (npm v3.10.10)
$  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.