Skip to content

Instantly share code, notes, and snippets.

@kotedo
Created December 9, 2014 18:57
Show Gist options
  • Save kotedo/b0a548f0bfcfdb7848d3 to your computer and use it in GitHub Desktop.
Save kotedo/b0a548f0bfcfdb7848d3 to your computer and use it in GitHub Desktop.
erlswitch
#!/usr/bin/env bash
# -*- mode: sh -*-
old=$(ls -l /usr/local/lib/erlang | awk '{print $11}')
others=$(ls -ld /usr/local/lib/erlang* | awk '{print $9}' | grep -v "^/usr/local/lib/erlang$")
default=${old}
declare -a arry
cat <<EOF
Select an Erlang version to be the next active version
Currently active: ${old}
EOF
counter=1
for i in $others
{
printf "\t%d) %s\n" $counter $i
arry[$counter]=$i
counter=$(expr $counter + 1)
}
# echo "OTHER[2]: ${arry[2]}"
echo
read -p "Select the new version or return for [${default}]: " answer
case ${answer} in
"")
answer=$default
;;
1|2|3|4|5|6|7|8|9|10)
# echo "Number ${answer} selected"
answer=${arry[$answer]}
;;
*)
printf "\nYou did not choose a valid item.\nNothing has been changed.\n\n"
;;
esac
rm /usr/local/lib/erlang
ln -s ${answer} /usr/local/lib/erlang
printf "\nActivated Erlang version '${answer}'.\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment