我有一个脚本,尽管我尽了最大的努力,但我还是不能去工作。我真的希望有人能帮上忙。对编程非常陌生,所以还在学习诀窍。我正在构建一个交互式shell脚本,它要求用户输入一个操作数,然后再放入另一个操作数,以生成第二个操作数的数学表。例如,我选择"+“&数字"2”(从15的范围),它会打印出"2+1=3,2+2 =4“等的表格,范围是10。这是我当前的脚本;
#!/bin/sh
echo "Please select the function you wish to perform from the following list"
echo " Multiplication = *"
echo " Addition = +"
echo " Subtraction = -"
echo " Division = /"
echo " Exponent = ^"
read s
echo "Please select a number between 1 and 15"
read n
i = 1
while [$i ‽ le 10]
do
if [$s = "*"]
then
echo "$n x $i = $((n*i))";
elif [ $s = "+"]
echo "$n + $i = $((n+i))";
elif [$s = "-"]
echo "$n - $i = $((n-i))";
elif [$s = "/"]
echo "$n / $i = $((n/i))";
elif [$s = "^"]
echo "$n ^ $i = $((n^i))";
fi
i = $((i+1))
done我知道我的while循环是不正确的,所以我非常感谢大家的帮助!谢谢!
发布于 2021-04-22 00:54:38
经过一些修改后:
#!/bin/sh
echo "Please select the function you wish to perform from the following list"
echo " Multiplication = *"
echo " Addition = +"
echo " Subtraction = -"
echo " Division = /"
echo " Exponent = ^"
read s
echo "Please select a number between 1 and 15"
read n
i=1
while [ "$i" -le 10 ]
do
if [ "$s" = "*" ]; then
echo "$n x $i = $((n*i))";
elif [ "$s" = "+" ]; then
echo "$n + $i = $((n+i))";
elif [ "$s" = "-" ]; then
echo "$n - $i = $((n-i))";
elif [ "$s" = "/" ]; then
echo "$n / $i = $((n/i))";
elif [ "$s" = "^" ]; then
echo "$n ^ $i = $((n^i))";
fi
i=$((i+1))
donehttps://stackoverflow.com/questions/67199762
复制相似问题