Created
January 5, 2017 23:15
-
-
Save NathanielInman/9b84884ab8b41cf378f19ff1f72fa616 to your computer and use it in GitHub Desktop.
Getting version from a package.json from shell
This file contains 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
# Using the package.json file itself: | |
# grep style | |
VERSION = `grep version package.json | cut -c 15- | rev | cut -c 3- | rev` | |
# sed style | |
VERSION = `sed -nE 's/^.*"version".*"(.*)",$/\1/p' package.json` | |
# awk style | |
VERSION = `awk '/version/{gsub(/("|",)/,"",$2);print $2};' package.json` | |
# Using npm run env instead | |
# grep style | |
VERSION = `npm run env | grep npm_package_version | cut -c 21-` | |
# sed style | |
VERSION = `npm run env | sed -nE 's/^npm_package_version=(.*)$/\1/p'` | |
# awk style | |
VERSION = `npm run env | awk '/npm_package_version/{print substr($0,21)}'` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment