红联Linux门户
Linux帮助

Ubuntu使用sh无法执行脚本文件的解决方法

发布时间:2014-11-17 22:08:10来源:linux网站作者:fdl19881

最近刚开始学习Linux Shell语言

看的是鸟哥的私房菜,里面有讲到执行shell脚本有两种方法:


1. 设置执行属性: chmod 755 file

执行(如果已经在当前目录) :    ./file


2. 使用:  sh file 执行

但是在vmware里装的Ubuntu 11.10却无法执行

#!/bin/bash 
declare -i s 
for (( i = 1; i <= 100;i = i+1 )) 
do  
s=s+i 
done 
echo "The count is ==> $s" 

使用第二种方法执行时出现:

test04_for.sh: 1: declare: not found
test04_for.sh: 3: Syntax error: Bad for loop variable

解决方法:

在终端中输入:

sudo dpkg-reconfigure dash

然后出现的界面中选择 NO

然后就能正确运行了。