1. 程式人生 > >Shell報錯bash^M /bin/bash^M: bad interpreter: No such file or directory

Shell報錯bash^M /bin/bash^M: bad interpreter: No such file or directory

問題:

在windows上寫的一個shell指令碼,在Linux上報錯,vim開啟的時候看了沒有啥問題,這種情況遇到很棘手,明明沒有問題的指令碼怎麼會報錯。
後來直接在另外一臺linux機器scp傳過來的同樣的指令碼就沒問題。第一個指令碼因為在windows上做過修改,所以懷疑是系統之間的預設編碼不同導致的報錯。報錯內容是^M,所以查詢這個報錯。

解決方法:

如果是單個檔案的話,直接vim開啟,命令模式用set ff?檢視一下編碼是dos還是unix,如果是dos直接用set ff=unix就可以了,如果是批量檔案的話,找到下面的方法(用sed或者vim進行替換的時候打^M不是shift+6,而是Ctrl+v+m):

基於 DOS/Windows 的文字檔案在每一行末尾有一個 CR(回車)和 LF(換行),
而 UNIX 文字只有一個換行,即win每行結尾為\r\n,而linux只有一個\n,
如果win下的文件上傳到linux,每行的結尾都會出現一個^M,(^M是ctrl+v,ctrl+m)
如果是單個文件的話,可以用vi開啟,執行 :%s/^M//g 來去掉^M,但如裡批量去
除的話就不能用vi了,
方法1: 用dos2unix工具,把win文件轉換成linux下文件命令:
find ./ -type f -print0 | xargs -0 dos2unix
如果想把linux下的文件轉換成win下的:
find .
/ -type f -print0 | xargs -0 unix2dos方法2: 用sed命令把win文件 轉換成linux下文件: find ./ -type f print0 | xargs -0 sed -i 's/^M$//' 把linux下的文件轉換成win下的 fild ./ -type f print0 | xargs -0 sed -i 's/$/^M/' 作者:小幕 連結:https://www.zhihu.com/question/22130727/answer/33814375 來源:知乎 著作權歸作者所有。商業轉載請聯絡作者獲得授權,非商業轉載請註明出處。

相關推薦

shell指令碼:-bash: xxx: /bin/sh^M: bad interpreter: No such file or directory

今天寫了一個shell指令碼,然後在執行的時候報錯,指令碼內容很簡單,僅供測試: Shell程式碼   #!/bin/sh   echo "test shell "   具體報錯資訊如下: Shell程式碼   [root@localhost test]# ./test.sh    -b

-bash: ./****.py: /usr/bin/python^M: bad interpreter: No such file or directory

在windows系統下寫的python指令碼,在linux下賦予許可權chmod +x xxx.py 以後,執行./xxx.py執行提示:bash: /usr/bin/autocrorder: /usr/bin/python^M: bad interpreter: No such file or

-bash: ./start.sh: /bin/sh^M: bad interpreter: No such file or directory 錯誤解決方案

問題描述:寫linux指令碼時。sh檔案中,在win環境下,編輯了.sh檔案,然後上傳到linux伺服器中,出現如下錯誤: -bash: ./start.sh: /bin/sh^M: bad interpreter: No such file or direc

linux sh腳本異常:/bin/sh^M:bad interpreter: No such file or directory

技術 異常 logs 信息 ima 轉換 linux中 bin ges 在Linux中執行.sh腳本,異常/bin/sh^M: bad interpreter: No such file or directory。這是不同系統編碼格式引起的:在windows系統中編輯的.s

sh腳本異常:/bin/sh^M:bad interpreter: No such file or directory

int 腳本 file bsp 字符 IT director linux inter 轉自:http://www.cnblogs.com/pipelone/archive/2009/04/17/1437879.html 在Linux中執行.sh腳本,異常/bin/sh^

bin/sh^M: bad interpreter: No such file or directory解決(轉載)

原帖子 問題:bin/sh^M: bad interpreter: No such file or directory 原因:.sh指令碼在windows系統下用記事本檔案編寫的。不同系統的編碼格式引起的。 解決方法:修改.sh檔案格式    (1)使用vi工

bin sh^M bad interpreter No such file or directory 解決

編寫了shell指令碼後,執行時有時會出現: ^M bad interpreter No such file or directory 的報錯,本文提供瞭解決方案 原因 Shell指令碼在windo

Shellbash^M /bin/bash^M: bad interpreter: No such file or directory

問題: 在windows上寫的一個shell指令碼,在Linux上報錯,vim開啟的時候看了沒有啥問題,這種情況遇到很棘手,明明沒有問題的指令碼怎麼會報錯。 後來直接在另外一臺linux機器scp傳過來的同樣的指令碼就沒問題。第一個指令碼因為在windows

Shell腳本報:-bash: ./switch.sh: /bin/bash^M: bad interpreter: No such file or directory

class height 格式 as3 nbsp 打開 title 腳本文件 執行命令 在學習shell中測試case參數命令代碼如下 #!/bin/bash #switch測試 case $1 in start) echo ‘start‘

Linux shell 腳本報:/bin/bash^M: bad interpreter: No such file or directory

詭異 參數 當前 use linu 信息 mar int 查看 今天遇到一個很詭異的問題,一直運行很正常的shell腳本失敗了,只是昨天增加了一個參數而已。 報錯信息: /bin/bash^M: bad interpreter: No such file or direc

inux指令碼 /bin/bash^M: bad interpreter: No such file or directory 的解決辦法

問題描述: 執行初始化指令碼的時候遇到一個很奇怪的錯誤,老是提示檔案或目錄找不到. 開啟指令碼反覆檢查,發現路徑都是對的 然後google了一下發現原來是我的檔案格式寫錯了,在windows下用檔案編輯器編輯的預設格式是dos 解決辦法: 在linux下需要把格式改為unix,這

一個小坑: -bash: ./backup.sh: /bin/bash^M: bad interpreter: No such file or directory 由於shell指令碼檔案被我在Windows下編輯過,出現上面錯誤的原因之一是指令碼檔案是DOS格式的, 即每一行的行尾以\r\n來標識

    由於shell指令碼檔案被我在Windows下編輯過,出現上面錯誤的原因之一是指令碼檔案是DOS格式的, 即每一行的行尾以\r\n來標識, 使用vim編輯器開啟指令碼, 執行::set ff? 可以看到DOS或UNIX的字樣. 使用se

轉:/bin/bash^M: bad interpreter: No such file or directory

nbsp unix bash 執行 bin vim dir file 文本 執行一個腳本full_build.sh 時, 一直是提示我: -bash: ./full_build.sh: /bin/bash^M: bad interpreter: No such file o

-bash: /usr/local/mysql/scripts/mysql_install_db: /usr/bin/perl: bad interpreter: No such file or directory

ase sed director direct bash 報錯 roo root pre 安裝 MySQL 初始化時,報錯如下: [[email protected] ~]# /usr/local/mysql/scripts/mysql_install_db --

bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory

yum 安裝一個軟體包,出現如下錯誤; -bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory –查詢python #whereis python python: /usr/bin/

/bin/bash^M: bad interpreter: No such file or directory

錯誤原因之一可能是你的指令碼檔案是DOS格式的。我們需要先檢視這個檔案是DOS格式的還是UNIX格式的, 還是MAC格式的vi filename :set ff?接下來可以看到dos或unix的字樣; 如果是dos格式, 用set ff=unix把它強制為unix格式的,然

-bash: /etc/init.d/nginx: /bin/bash^M: bad interpreter: No such file or directory

-bash: /etc/init.d/nginx: /bin/bash^M:bad interpreter: No such file or directory這個使為了弄nginx自啟的,然後在官網找

阿里雲centos7 yum命令無效-bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory

-bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory 原因:由於本人伺服器安裝上python3版本後導至liunx找不到自帶的python2版本路徑;

mysql MHA Can't exec "mysqlbinlog": No such file or directory at /usr/local/share/perl5/MHA/BinlogManager.pm line 99.

IT oca ilo 引入 cut found with while keepal 如果發現如下錯誤: Can‘t exec "mysqlbinlog": No such file or directory at /usr/local/share/perl5/MHA/Bi

登入伺服器 setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory 解決

登入伺服器提示: -bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory 使用cat 檢視檔案的時候沒用問題 使用vim 開啟編輯的時候中文都是亂碼