天天看點

linux下執行腳本(shell,python等),提示Command not found解決辦法

原文位址:http://www.cnblogs.com/GordonWorld/archive/2012/03/19/2406225.html

Linux下執行.sh腳本錯誤:bin/sh^M: bad interpreter: No such file or directory

同樣的python檔案也是,即使在scripts開頭指定了運作程式!

原因是腳本是在windows系統下編寫的。不同系統的編碼格式引起的。

轉行檔案的編碼格式:

1、確定使用者對檔案有讀寫及執行權限

    chmod x test.sh

2、然後修改檔案格式

   (1)使用vi工具

      vi test.sh

    (2)利用如下指令檢視檔案格式 

     :set ff 或 :set fileformat 

     可以看到如下資訊 

     fileformat=dos 或 fileformat=unix 

     (3) 利用如下指令修改檔案格式 

     :set ff=unix 或 :set fileformat=unix 

     :wq (存盤退出)

3、最後再執行

    ./test.sh

繼續閱讀