while 循环的脚本错误

while 循环的脚本错误

我在执行 bash 脚本时出现以下错误。

#!/bin/bash

mynum=1

while [ $mynum -le 10 ]
do
    echo $mynum
    mynum= $(( $mynum + 1 ))
    sleep 0.5
done

错误:

$./wl
1
./wl: line 8: 2: command not found
1
./wl: line 8: 2: command not found
1
./wl: line 8: 2: command not found
1
./wl: line 8: 2: command not found
1
./wl: line 8: 2: command not found
1
./wl: line 8: 2: command not found
1
./wl: line 8: 2: command not found
1
./wl: line 8: 2: command not found

答案1

增加变量的正确方法如下(如何在 bash 中增加变量?

#!/bin/bash
mynum=1
while [ $mynum -le 10 ]
do
    echo $mynum
    mynum=$((mynum+1))
    sleep 0.5
done

相关内容