Skip to content

Instantly share code, notes, and snippets.

@ThePlenkov
Forked from DarrenN/get-npm-package-version
Last active April 10, 2021 00:29
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 ThePlenkov/1614d885e37002fcd83272d3ae2d1d9f to your computer and use it in GitHub Desktop.
Save ThePlenkov/1614d885e37002fcd83272d3ae2d1d9f to your computer and use it in GitHub Desktop.
Extract version from package.json (NPM) using bash / shell
# Version key/value should be on his own line
PACKAGE_VERSION=$(cat package.json \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g'
| awk '{$1=$1};1'
)
echo $PACKAGE_VERSION
@ThePlenkov
Copy link
Author

added awk '{$1=$1};1' to remove trailing whitespace

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