Skip to content

Instantly share code, notes, and snippets.

@tobiashm
Created October 6, 2015 07:04
Show Gist options
  • Save tobiashm/bcd049716bd6736808c8 to your computer and use it in GitHub Desktop.
Save tobiashm/bcd049716bd6736808c8 to your computer and use it in GitHub Desktop.
Version check in Bash
awk -v ver="$(npm -v)" 'BEGIN { if (ver > 2.0) exit 1; }' && npm i -g npm@2
@tobiashm
Copy link
Author

tobiashm commented Oct 6, 2015

Using awk since Bash doesn't handle decimal numbers

@tobiashm
Copy link
Author

tobiashm commented Oct 6, 2015

Alternative using Ruby:

ruby -e "\`npm i -g npm@2\` if '`npm -v`'<'2.0.0'"

@tobiashm
Copy link
Author

tobiashm commented Oct 6, 2015

Another alternative:

IFS=. read major minor patch <<<"$(npm -v)"; (( major < 2 )) && npm i -g npm@2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment