This bash script is nasty.