Creating a calculator script

后端 未结 7 2135
悲哀的现实
悲哀的现实 2020-12-17 06:18

I am trying to make a calculator with a bash script. The user enters a number, chooses whether they wish to add, subtract, multiply or divide. Then the user enters a second

7条回答
  •  时光取名叫无心
    2020-12-17 06:47

    Wrapping Code in a Loop

    If you just want to wrap your code in a Bash looping construct, and are willing to hit CTRL-C to terminate the loop rather than do something more fancy, then you can wrap your code in a while-loop. For example:

    while true; do
        : # Your code goes here, inside the loop.
    done
    

    Just make sure to move your unconditional exit statement out of the body of the loop. Otherwise, the loop will terminate whenever it reaches that line.

提交回复
热议问题