更新时间:2023-11-21 19:12:28
赋值中[
之后需要一个空格,在=
之前或之后都不需要空格. $(($i+1)))
会尝试执行((...))
表达式的输出,我确定这不是您想要的.另外,您在数组名称前缺少$
.
Need a space after [
and no space before or after =
in the assignment. $(($i+1)))
would try to execute the output of the ((...))
expression and I am sure that's not what you want. Also, you are missing a $
before the array name.
更正这些问题后,您的while循环将为:
With these things corrected, your while loop would be:
#!/bin/bash
i=0
while [ "$i" -le "${#myarray[@]}" ]
do
echo "Welcome $i times"
i=$((i + 1))
done
i=$((i + 1))
也可以写为((i++))
[ ... ]
i=$((i + 1))
can also be written as ((i++))
[ ... ]
另请参阅: