歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Ubuntu 使用sh 無法執行腳本文件的解決方法

Ubuntu 使用sh 無法執行腳本文件的解決方法

日期:2017/2/28 15:53:28   编辑:Linux教程

最近剛開始學習Linux Shell語言

看的是鳥哥的私房菜,《鳥哥的Linux私房菜 基礎學習篇(第三版)PDF高清晰 》下載見 http://www.linuxidc.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.linuxidc.com/topicnews.aspx?tid=2

Copyright © Linux教程網 All Rights Reserved