#!/bin/bash
for ((i = 10 ; i>=0 ; i--))
do
echo $i
done
Ubuntu下执行报错:Syntax error: Bad for loop variable
原因在于:从 ubuntu 6.10 开始,ubuntu 就将先前默认的bash shell 更换成了dash shell;其表现为 /bin/sh 链接倒了/bin/dash而不是传统的/bin/bash。
问题1:那为什么#!/bin/bash没有起作用?
./执行会读取#!/bin/bash指定shell解析器,脚本需要执行权限
用sh 执行不会读取#!/bin/bash,此时相当于执行/bin/sh shell脚本作为参数传入,脚本无需执行权限,只需要读取权限
解决方案1:
执行sudo dpkg-reconfigure dash ,选择NO
解决方案2:
修改循环
for i in `seq 1 10`
do
echo $i
done
OR
for i in {0..10}
do
echo $i
done