unix/windows回車問題(\r\n or \n) or shell腳本執(zhí)行錯誤 $'\r':command not found
Posted on 2019-10-25 10:41 宋鵬 閱讀(574) 評論(0) 編輯 收藏 引用 所屬分類: Linuxunix/windows回車問題
shell腳本執(zhí)行錯誤 $'\r':command not found
存現(xiàn)這種錯誤是因為 編寫的 shell腳本是在win下編寫的,每行結(jié)尾是\r\n 的Unix 結(jié)果行是\n
所以在Linux下運行腳本 會任務\r 是一個字符,所以運行錯誤,需要把文件轉(zhuǎn)換下。
存現(xiàn)這種錯誤是因為 編寫的 shell腳本是在win下編寫的,每行結(jié)尾是\r\n 的Unix 結(jié)果行是\n
所以在Linux下運行腳本 會任務\r 是一個字符,所以運行錯誤,需要把文件轉(zhuǎn)換下。
1.單個文件轉(zhuǎn)換:
運行腳本
dos2unix 腳本名
OK
2.整個目錄中的文件做dos2unix操作:
$ find . -type f -exec dos2unix {} \;
其中具體命令的解釋如下:
find .
= find files in the current directory
-type f
= of type f
-exec dos2unix {} \;
= and execute dos2unix on each file found
參考:
https://blog.csdn.net/Lnho2015/article/details/51322289
https://blog.csdn.net/yuliying/article/details/75912021
https://blog.csdn.net/liuxiangke0210/article/details/80395707
參考:
https://blog.csdn.net/Lnho2015/article/details/51322289
https://blog.csdn.net/yuliying/article/details/75912021
https://blog.csdn.net/liuxiangke0210/article/details/80395707