function unsetvars { unset word unset poem unset poems unset line unset counter unset linenumber } function getpoem { #get number of lines in file counter=`wc -l < $poems` #get random line number linenumber=$[ ( $RANDOM % $counter ) + 1 ] #get the line poem=`sed -n "${linenumber}p" < $poems` } function echopoem { echo #go through each word for word in $poem; do #if the word isn't a newline character, add it to the output if [ "${word}" == "/" ]; then echo $line; unset line; else line=$line" ${word}"; fi done echo $line echo } function printhaiku { unsetvars poems=$1 getpoem echopoem unsetvars }