Skip to content

Instantly share code, notes, and snippets.

@sgen
Created August 8, 2020 20:47
Show Gist options
  • Save sgen/8f6d39d1641d797c8e2ac79020625e03 to your computer and use it in GitHub Desktop.
Save sgen/8f6d39d1641d797c8e2ac79020625e03 to your computer and use it in GitHub Desktop.
Bash Semantic Versioning Validation Regular Expression
#!/bin/bash
version="$1"
[[ -z "$version" ]] && { echo "no version provided" >&2; exit 1; }
semver_regexp='^[vV]?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(\-([0-9A-Za-z]*)(\.([0-9A-Za-z]*))*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-])*)?$'
[[ ! "$version" =~ $semver_regexp ]] && { echo "$version is not valid" >&2; exit 1; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment