bash shell while循環超出了條件表達式

bash shell while循環超出了條件表達式

在我的問題中,看起來像jvalue 和ivaluereach 6;哪裡i應該只跑到5.有人可以解釋一下嗎?

i=0;
j=0;
echo "values of $i and $j" > debug.txt;
while [ $j -le 5 ]
do
    j=expr $j + 1
    i=expr $i + 1
    echo "values of $i and $j" >> debug.txt
done;
cat debug.txt;

輸出 :

value of i is  0 and j is  0
value of i is  1 and j is  1
value of i is  2 and j is  2
value of i is  3 and j is  3
value of i is  4 and j is  4
value of i is  5 and j is  5
value of i is  6 and j is  6

答案1

您的腳本不起作用的原因是您正在使用-le.這-le會導致您的腳本認為當它達到 5 時,它仍然會執行,因為它等於 5 -lt

相關內容