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


最近刚开始学习Linux Shell语言

看的是鸟哥的私房菜,《鸟哥的Linux私房菜 基础学习篇(第三版)PDF高清晰 》下载见 http://www.bkjia.net/thread-2268-1-1.html 。里面有讲到执行shell脚本有两种方法:

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

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

2. 使用:  sh file 执行

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

  1. #!/bin/bash  
  2. declare -i s  
  3. for (( i = 1; i <= 100;i = i+1 ))  
  4. do   
  5.     s=s+i  
  6. done  
  7. 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

然后就能正确运行了。

更多Ubuntu相关信息见Ubuntu 专题页面 http://www.bkjia.com/topicnews.aspx?tid=2

相关内容