MLUG Bash Scripting Workshop 25/04/08 | ||
---|---|---|
Prev | Index | Next |
Hopefully if you've been with this from the beginning you will be able to read through example07 below and understand what's going on, or more correctly, what would go on if the script was run.
While the script might seem silly, it incorporates most of what we've been discussing up to this point. I would say that if you can understand it you probably wouldn't have to much trouble copying any or all of it over and adopting it for some other purpose. If you've come that far, you are capable of doing yourself some useful Bash scripting.
Have a go with this script before we move on.
#!/bin/bash # example07 # silly 20080415rm # Playing around to illustrate a few techniques clear echo -e "\n\t\t\tWhat does `whoami` want to do?\n" echo -e "\t\t\tMake a selection from the following by" echo -e "\t\t\ttyping in the corresponding number then" echo -e "\t\t\thitting enter. \c" sleep 1 echo -e "\n\n\t\t\t1 Do nothing" echo -e "\t\t\t2 Get the time and date" echo -e "\t\t\t3 Do something silly" echo -e "\t\t\t\t\c" read response case $response in 1) echo -e "\n\n\t\t\tLooks like we're feeling lazy today :^)\n\n\n" sleep 5 ;; 2) echo -e "\n\n\t\t\t`date`" sleep 4 clear ;; 3) clear silly=0 while [ $silly -lt 10 ]; do echo -e "\n\n\n\t\t\c" sleep 1 echo -e "`whoami` is a darn nice person, I \c" echo -e "don't care what anybody says! \c" sleep 1 clear let silly=$silly+1 done sleep 2 ;; *) clear echo -e "\n\n\t\t\tYou did not respond correctly!!" sleep 2 echo -e "\n\t\tYou are lucky I didn't put you in an infinit loop!" sleep 2 echo -e "\n\t\tYou will now have to wait 1 minute before you get" echo -e "\t\tyour command prompt back \c" sleep 10 echo -e "\n\n\n\n" ;; esac #end of script