shell 脚本运行时:Bad for loop variable
·
a.sh: 2: a.sh: Syntax error: Bad for loop variable
#!/bin/sh
for ((i=1;i<=100;i+=1))
do
echo ${i}
done
用ubuntu系统运行时: sh a.sh 报错

因为Ubuntu为了加快开机速度,用dash代替了传统的bash,所以我们这样执行就没问题.
执行方式应该是: bash a.sh
因为在Ubuntu中的sh不支持 for ((i=1;i<=100;i+=1)) 这种写法
举例:
for i in {1..10}
#!/bin/sh
for i in {1..10}
do
echo ${i}
done

bash和sh执行的结果不同
更多推荐
所有评论(0)