linux下執行shell腳本時報錯:-bash: ./a.sh: /bin/bash^M: bad interpreter: No such file or directory。
原因是windows下的文件是dos格式,即每一行結尾以\r\n來標識,而linux下的文件是unix格式,行尾則以\n來標識。
查看文件格式有三種方法:
1.cat -A ,如果輸出結果中行末尾是^M,則是unix格式。
2.vim ,編輯文件,執行“:set ff”,若執行結果爲fileformat=dos則爲dos格式,若執行結果爲fileformat=unix則爲unix格式。
3.od -t x1 ,以16進制查看文件,若輸出結果中存在“0d 0a”則爲dos格式,如果只有“0a”則爲unix格式。其中“0d”即爲回車符“\r”,“0a”即爲換行符“\n”。
修改文件格式有三種方式:
1.sed -i “s/\r//” 或sed -i “s/^M//” ,直接將回車符替換爲空字符串。
2.vim ,編輯文件,執行“: set ff=unix”,將文件設置爲unix格式,然後執行“:wq”,保存退出。
3.dos2unix 或busybox dos2unix ,如果提示command not found,可以使用前兩種方法。
更多精彩
join("q_qun","1071834648");