我不明白,爲什麼在這段代碼問題使用「MUL」和「國防部」運營商在猛砸
echo "Please, give me two numbers:"
echo 1:
read a
echo 2:
read b
echo "a = $a"
echo "b = $b"
OPT="Sum Sub Div Mul Mod"
select opt in $OPT; do
if [ $opt = "Sum" ]; then
sum=$(echo $a + $b | bc -l)
echo "SUM is: $sum"
elif [ $opt = "Sub" ]; then
sub=$(echo $a - $b | bc -l)
echo "SUB is: $sub"
elif [ $opt = "Div" ]; then
div=$(echo $a/$b | bc -l)
echo "DIV is: $div"
elif [ $opt = "Mul" ]; then
mul=$(echo $a * $b | bc -l)
echo "MUL is: $mul"
elif [ $opt = "Mod" ]; then
mod=$(echo $a % $b | bc -l)
echo "MOD is: $mod"
else
clear
echo "wrong choise"
exit
fi
done
執行正確總結,SUB和DIV,但如果我想要做的MUL或MOD操作,它給我一個錯誤:
(standard_in) 1: syntax error
(standard_in) 1: illegal character: ~
(standard_in) 1: illegal character: ~
是的謝謝。 我也發現這個解決方案: mul = $(echo「$ a * $ b」| bc -l) 也適用於'%'。 – Kyrol
是的,任何引用都可以,所以拿一個你喜歡的 – unbeli