Last active
June 4, 2017 23:39
-
-
Save mortie/ccd5b227fe6111fea017e7258d77d9a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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