0

so i am trying to script the commands for simple mathematics such as addition , subtraction , multiplication and division , i started to write a script for addition but there is a problem ; here is my script

echo "choose two numbers"
read a
read b 
select operation in addition substraction division multiplication
    do case $operation in
    "addition")
        echo "result of the addition=" "$ ((expr $a + $b))";;
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • "but there is a problem" is not useful to someone trying to help debug. What is the exact problem you are having, what is the expected behavior, and what is the actual behavior? – blackbrandt Sep 20 '21 at 14:08
  • i am simply looking for the correct code for addition , substraction or division in bash , couldnt find online – Mohamed ali Lemkecher Sep 20 '21 at 14:11
  • So something like [How to add numbers in a bash script](https://stackoverflow.com/questions/6348902/how-can-i-add-numbers-in-a-bash-script)? – blackbrandt Sep 20 '21 at 14:12
  • It's either `$(($a + $b))` or `$(expr $a + $b)`. You combined both of them, which is wrong. – Barmar Sep 20 '21 at 15:00
  • I tried to correct it but still tells me error in syntax that's the syntax : "addition") echo "the resulut is"=$(($a + $b)) – Mohamed ali Lemkecher Sep 20 '21 at 19:25
  • Or, ideally, just `$((a + b))`. Which has an odd corner case by default, but `set -u` deals with that corner case. Also, don’t forget `esac` and `done`; not sure if your snippet omits it for brevity or if it’s really missing. – Andrej Podzimek Sep 20 '21 at 21:15

0 Answers0