Results 1 to 5 of 5
Hey guys I'm new but trying to figure something out, I'm teaching myself the basic's of Shell Scripting, and decided a Calculator of sorts is as good a place as ...
- 04-13-2011 #1Just Joined!
- Join Date
- Apr 2011
- Posts
- 3
Noob Shell Scripting
Hey guys I'm new but trying to figure something out, I'm teaching myself the basic's of Shell Scripting, and decided a Calculator of sorts is as good a place as any to start, However what I want to do is after each case statement to return you to the Original Question "Select Add...." is there a command to do this?
I would guess its a form of flagging the start point and referencing it in each case. Heres My code so far
Code:echo "Select Add (+), Sub (-), Multi(x), Divide(/)" read Opr echo "First Number" read Num1 echo "2nd Number" read Num2 case $Opr in +) Sum=`expr $Num1 + $Num2` echo "Answer = $Sum" ;; -) Sum=`expr $Num1 - $Num2` echo "Answer = $Sum" ;; /) Sum=`expr $Num1 / $Num2` echo "Answer = $Sum" ;; x|X) Sum=`expr $Num1 \* $Num2` echo "Answer = $Sum" ;; *) echo "Error, try again - Press anything to continue" ;; esac
- 04-13-2011 #2
Wrap the whole thing in a while loop, and break the loop if the user wants to exit.
something like:
Code:while [ 1 ]; do echo "Continue?" read input if [ $input = "no" ]; then break fi # the rest of your calculator code done
- 04-13-2011 #3Just Joined!
- Join Date
- Apr 2011
- Posts
- 3
- 04-14-2011 #4Just Joined!
- Join Date
- Apr 2011
- Posts
- 3
Why is the goto command not considered proper coding? surely if it works its grand?
- 04-14-2011 #5
goto is incredibly easy to abuse leading to unreadable and unmaintainable code which is a bad thing. Write your code as if the guy maintaining it after you it is a psycho with an axe and your address.
More infoIf we hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate! (Zapp Brannigan)
My new blog. It's probably not as good as I think it is.


Reply With Quote
