日期:2014-05-16  浏览次数:20642 次

【Linux】ubuntu报错Syntax error: "(" unexpected解决方法

今天跟着练习一个shell scripts,内容如下:

=======================================
#!/bin/bash
# Using for and loop
# allen 2010/04/13
declare -i s # <==变量宣告
for (( i=1; i<=100; i=i+1 ))
do
??????? s=s+i
done
echo "The count is =l
=======================================

但是运行时总是报下面这个错,如下:

test11-loop.sh: 5: Syntax error: Bad for loop variable

几经查找语法,没有问题,后来在网上找到问题原因:

代码对于标准bash而言没有错,因为Ubuntu为了加快开机速度,用dash代替了传统的bash,是dash在捣鬼。
解决方法是 取消dash
sudo dpkg-reconfigure dash
在选择项中选No,即可。