Created
October 6, 2015 07:04
-
-
Save tobiashm/bcd049716bd6736808c8 to your computer and use it in GitHub Desktop.
Version check in Bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
awk -v ver="$(npm -v)" 'BEGIN { if (ver > 2.0) exit 1; }' && npm i -g npm@2 |
Alternative using Ruby:
ruby -e "\`npm i -g npm@2\` if '`npm -v`'<'2.0.0'"
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
Using awk since Bash doesn't handle decimal numbers