Skip to content

Instantly share code, notes, and snippets.

@Sylvain-Bugat
Forked from yvele/get-npm-package-version.sh
Last active April 14, 2017 20:19
Show Gist options
  • Save Sylvain-Bugat/f6ffad0eab34394159fb to your computer and use it in GitHub Desktop.
Save Sylvain-Bugat/f6ffad0eab34394159fb to your computer and use it in GitHub Desktop.
Extract version from package.json (NPM) using bash / shell / awk
# One command version using awk
PACKAGE_VERSION=$( awk -F: '$1 ~ /"version"/ { split($2,array,"\""); print array[2] ; exit }' package.json )
echo "${PACKAGE_VERSION}"
@4F2E4A2E
Copy link

# Gitlab CI working version
PACKAGE_VERSION=$(cat package.json | grep version | head -1 | awk -F= "{ print $2 }" | sed 's/[version:,\",]//g' | tr -d '[[:space:]]')

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