Skip to content

Instantly share code, notes, and snippets.

@NathanielInman
Created January 5, 2017 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NathanielInman/9b84884ab8b41cf378f19ff1f72fa616 to your computer and use it in GitHub Desktop.
Save NathanielInman/9b84884ab8b41cf378f19ff1f72fa616 to your computer and use it in GitHub Desktop.
Getting version from a package.json from shell
# 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