(standard_in) 1: 我的 bash 脚本中的语法错误 - bc 错误
(standard_in) 1: syntax error in my bash script - bc error
我正在尝试创建一个计算器,在 shell 脚本上进行基本的数学运算,但当我尝试 multiply 两个数字,我试图找到一些解决方案,但直到现在都没有帮助我。
这是我的代码:
echo "====== Calculator ======"
echo " "
# It will save both numbers to the variables
echo "Type a number: "
read numA
echo "Type another number: "
read numB
echo " "
# It will give a list of possible operations
echo "Choose an option"
echo "------------------"
echo "1)Addition"
echo "------------------"
echo "2)Subtraction"
echo "------------------"
echo "3)Multiplication"
echo "------------------"
echo "4)Division"
echo "------------------"
echo " "
read -s opt
# It will make the math behind each operation
case $opt in
1)result=`echo $numA + $numb | bc`;;
2)result=`echo $numA - $numB | bc`;;
3)result=`echo $numA * $numB | bc`;;
4)result=`echo "scale=2; $numA / $numB" | bc`;;
esac
echo "Result: $result"
在“*”前加一个反斜杠,即
3)result=`echo $numA \* $numB | bc`;;
我正在尝试创建一个计算器,在 shell 脚本上进行基本的数学运算,但当我尝试 multiply 两个数字,我试图找到一些解决方案,但直到现在都没有帮助我。
这是我的代码:
echo "====== Calculator ======"
echo " "
# It will save both numbers to the variables
echo "Type a number: "
read numA
echo "Type another number: "
read numB
echo " "
# It will give a list of possible operations
echo "Choose an option"
echo "------------------"
echo "1)Addition"
echo "------------------"
echo "2)Subtraction"
echo "------------------"
echo "3)Multiplication"
echo "------------------"
echo "4)Division"
echo "------------------"
echo " "
read -s opt
# It will make the math behind each operation
case $opt in
1)result=`echo $numA + $numb | bc`;;
2)result=`echo $numA - $numB | bc`;;
3)result=`echo $numA * $numB | bc`;;
4)result=`echo "scale=2; $numA / $numB" | bc`;;
esac
echo "Result: $result"
在“*”前加一个反斜杠,即
3)result=`echo $numA \* $numB | bc`;;