实例程序是demo.sh
#!/bin/bash
windows='windows'
string='2 3 4 5 6'
if [ ! -z $windows ];then
arry=($string)
total=0
for n in ${arry[@]}
do
(( total+=n ))
done
fi
echo $total
在ubuntu10.04下运行 sh -x demo.sh 出现下面的错误
demo.sh: 5: Syntax error: "(" unexpected (expecting "fi")
是ubuntu bash环境的原因 ,解决方法是执行一条命令dpkg-reconfigure dash 。然后选择NO,就OK了