谁能帮我理解为什么这是不工作?有人能给我指出正确的方向来学习如何做吗?
x=0
while [ $x = 0 ]
do
echo “times tables”
echo "please select"
echo "1) addition"
echo "2) subtraction"
echo "3) multiply"
echo "4) division"
echo "5) exponent"
read symbol
case "$symbol" in
addition)
echo "enter the number you wish"
read a
for ((i=1; i<=15; i++))
do
b=$((a +i))
echo "$a+$i=$b"
sleep 2
x=0
echo try another “yes or no”
read answer
if $yes
x = 0
if $no
x=
case "$symbol" in
subtraction)
echo "enter the number you want"
read a
for ((i=1; i<=15; i++))
do
b=$((a -i))
echo "$a-$i=$b"
我基本上是在尝试编写一个程序用户选择符号然后可以用它做乘法表。然而,我希望它在完成时循环回到符号的选择,或者在里面有另一个循环,让它们继续与它们在一起。当我把它们分开时,它似乎起作用了。就像如果我只是删除了询问什么符号的选项,而只是提供了一个数字的加法和用户输入,那么加法乘法表将工作。然后再做减法。然而,一旦我尝试添加一个循环。它停止。
试试这个:
x=0
while [ $x = 0 ]
do
echo “times tables”
echo "please select"
echo "1) addition"
echo "2) subtraction"
echo "3) multiply"
echo "4) division"
echo "5) exponent"
read symbol
case "$symbol" in
1)
echo "enter the number you wish"
read a
for ((i=1; i<=15; i++))
do
b=$((a + i))
done
echo "$a+$i=$b"
sleep 2
x=0
;;
2) echo "not implemented" ;;
3) echo "not implemented" ;;
4) echo "not implemented" ;;
5) echo "not implemented" ;;
*) echo "not implemented" ;;
esac
echo try another “yes or no”
read answer
if [ "$answer" == "yes" ]
then {
x = 0
echo "[ choose an option ]"
}
else {
echo "exiting..."
break
}
fi
done