Creating a calculator script

后端 未结 7 2153
悲哀的现实
悲哀的现实 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:37

    How about this

    calc ()
    {
      (( d = $1 ))
      echo $d
    }
    

    output

    $ calc '6 + 2'
    8
    
    $ calc '6 - 2'
    4
    
    $ calc '6 * 2'
    12
    
    $ calc '6 / 2'
    3
    

提交回复
热议问题