Bash Scripting for Buffoons - Eggtimer Script

Ceri Shaw
12/16/15 05:02:45AM
@ceri-shaw

Eggtimer Script



⇦ Back to 'Bash Scripting For Buffoons'

Yes folks it's an eggtimer, or perhaps more accurately an interval timer. You can tweak it to measure any interval you like but as it stands, it does hard and soft-boiled eggs. It uses the 'case' menu format and a nested 'for' loop to achieve the desired effect. For some reason I decided to call 'menu' as a function. If you want it to beep at the end of the interval you need to have the system 'beep' program installed. For those of you running Ubuntu, it's in the repositories.

#!/bin/bash
# nested for loop
menu () {
echo "======================================="
echo "Please select from the following menu:-"
echo " "
echo "1 Soft boiled."
echo "2 Hard boiled."
echo " "
read NAME
case "$NAME" in
1)
for i in 1 2 3 4
do
echo -n "Min $i: "
for j in 5 10 15 20 25 30 35 40 45 50 55 60
do
sleep 5
echo -n "$j "
done
echo #output newline
done ;;
2)
for i in 1 2 3 4 5 6 7 8 9 10
do
echo -n "Min $i: "
for j in 5 10 15 20 25 30 35 40 45 50 55 60
do
sleep 5
echo -n "$j "
done
echo #output newline
done ;;
*) echo "Not a valid option!" ;;
esac
}
menu
beep
exit 0



An exhilarating screen shot of the Bash Eggtimer in action!

Download the script here (.txt) Bash Eggtimer Script