所以我正在linux终端上编写一个程序,我的程序有两个部分。第一部分是除法,第二部分是计算一些数字的 MOD。退出第一部分的方法是将 999 放入任何一个要除的输入中。
我的问题是即使用户输入 999 作为第一个输入,用户也必须输入第二个数字。我想知道这些是否类似于在 Windows 中可以执行 goto :someOtherLocation 在 linux 中的东西。这是代码:
echo "Enter the number to divide (dividend) (enter 999 to quit):"
read numberOne
[IF NUMBERONE = 999, JUMP TO SECONDPART]
echo "Enter the number to divide (divisor) (enter 999 to quit):"
read numberTwo
while [ "$numberOne" -ne '999' ] && [ "$numberTwo" -ne '999' ]
do
while [ "$numberTwo" -eq 0 ]
do
echo "You cannot divide by 0, please enter another number:"
read numberTwo
done
RESULT=$(echo "$numberOne/$numberTwo" | bc -l)
echo $numberOne / $numberTwo = $RESULT
echo $numberOne / $numberTwo = $RESULT >> results.txt
echo "Enter the number to divide (dividend) (enter 999 to quit):"
read numberOne
echo "Enter the number to divide (divisor) (enter 999 to quit):"
read numberTwo
done
SECONDPART
counter=1
totalCount=0
temporal=0
while [ "$counter" -lt '101' ]
do
temporal=$( expr $counter % 5)
echo $counter MOD 5 = $temporal
echo $counter MOD 5 = $temporal >> results.txt
totalCount=$(echo "$totalCount+$temporal" | bc -l)
counter=$(echo "$counter+1" | bc -l)
done
average=$(echo "$totalCount/100" | bc -l)
echo The average of all the MODs is $average >> results.txt
如上所示,如果输入是 999,我想直接从输入跳到第二部分。