Skip to content

Instantly share code, notes, and snippets.

@xianghuzhao
Created November 2, 2016 10:01
Show Gist options
  • Save xianghuzhao/a70bc2bb352467c0233bde931812ae5f to your computer and use it in GitHub Desktop.
Save xianghuzhao/a70bc2bb352467c0233bde931812ae5f to your computer and use it in GitHub Desktop.
Get python version in shell
#!/bin/sh
get_python_version() {
version_str=$(python -V 2>&1)
temp=${version_str##* }
python_version_major=${temp%%.*}
temp=${temp#*.}
python_version_minor=${temp%%.*}
}
get_python_version
echo "Python version: ${python_version_major}.${python_version_minor}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment