Skip to content

Instantly share code, notes, and snippets.

@mortie
Last active June 4, 2017 23:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mortie/ccd5b227fe6111fea017e7258d77d9a4 to your computer and use it in GitHub Desktop.
Save mortie/ccd5b227fe6111fea017e7258d77d9a4 to your computer and use it in GitHub Desktop.
#!/bin/sh
py2=$(which python2 2>/dev/null)
py3=$(which python3 2>/dev/null)
py=$(which python 2>/dev/null)
oldcol="\033[31;1m"
newcol="\033[32;1m"
arrowcol="\033[33;1m"
if [ -z "$py2" ]; then
echo "Python 2 doesn't exist."
exit 1
elif [ -z "$py3" ]; then
echo "Python 3 doesn't exist."
exit 1
elif [ -z "$py" ]; then
echo "Python doesn't exist."
exit 1
fi
printf "${oldcol}%s" "$(python --version 2>&1)"
if python --version 2>&1 | grep 'Python 2' > /dev/null; then
sudo rm "$py"
sudo ln -s "$py3" "$py"
elif python --version 2>&1 | grep 'Python 3' > /dev/null; then
sudo rm "$py"
sudo ln -s "$py2" "$py"
else
echo "Your python is neither version 2 nor 3, sorry."
exit 1
fi
printf " ${arrowcol}=> ${newcol}%s\n" "$(python --version 2>&1)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment