Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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