Menu w/ Counting

  • Thread starter Thread starter Moonshine2183
  • Start date Start date
M

Moonshine2183

So I'm trying to construct a menu that leads to three different features. Feature one counts from 0 to a user input value. Feature 2 counts down from a user input value to 0. And feature 3 simply exits the program.

So far I've gotten feature 1 (the count up feature) to work, and feature 3 (the quit feature to work). However, I'm stuck on trying to get feature 2 (the count down feature) to work.

Here's my program

#!/bin/sh
clear
count=0
while [ $count -eq 0 ]
do
echo "To count up or down; Enter the number of your choice"
echo "1. Up"
echo "2. Down"
echo "3. Quit"
read choice
if [ $choice -ne 3 ]
then
echo "Enter number to count to"
read num
fi
case $choice in
1) counter=0
until [ $counter = "$num" ]
do
counter=`expr $counter + 1`
echo $counter
done
;;
2) counter="$num"
until [ $counter = "0" ]
do
counter=`expr $counter - 1`
done
;;
3) exit 1
;;
*) echo "Invalid Selection !"
;;
esac
sleep 3
done

Any advice?

Continue reading...
 
Back
Top