私は学校プロジェクトのためにBASHで電卓を作っています。ただし、乗算コードは機能しません。私の計算機BASHスクリプトで乗算を修正する方法
#!/bin/bash
input="yes"
while [[ $input = "yes" ]]
do
#type in the number that correponds to math operation you want to do
PS3="Press 1 for Addition, 2 for subtraction, 3 for multiplication
4 for division: "
select math in Addition Subtraction Multiplication Division
do
case "$math" in
Addition)
#enter numbers
echo "Enter first no:"
read num1
echo "Enter second no:"
read num2
result=`expr $num1 + $num2`
echo Answer: $result
break
;;
#enter numbers
Subtraction)
echo "Enter first no:"
read num1
echo "Enter second no:"
read num2
result=`expr $num1 - $num2`
echo Answer: $result
break
;;
#thing that needs to be fixed
Multiplication)
echo "Enter first no:"
read num1
echo "Enter second no:"
read num2
$result= expr $num1 * $num2
echo Answer: $result
break
;;
#enter numbers
Division)
echo "Enter first no:"
read num1
echo "Enter second no:"
read num2
result=$(expr "scale=2; $num1/$num2" | bc)
echo Answer = $result
break
;;
*)
break
;;
esac
done
done
を使用
expr
を使用。 – chepner期待される出力とは何かを書いて、人々があなたを助けてくれるようにするためのエラーとは何ですか? [here](https://stackoverflow.com/help/how-to-ask)を参照してください。 –