Shell—常見報錯問題

bash:$'\r': command not foundbash

形成這個問題的緣由是Windows環境下換行的「\r」到了Linux環境下不可以識別了,由於Linux環境下默認的換行符爲「\n」,咱們只須要把文件轉成unix就好。使用 dos2unix 工具實現該轉換。工具

# 1.安裝 dos2unix 工具
[root@localhost ~]# apt install dos2unix         # Ubuntu系統
[root@localhost ~]# yum -y install dos2unix   # Centos系統

# 2.轉換文件
[root@localhost ~]# chmod 755 test.sh
[root@localhost ~]# dos2unix test.sh

# 3.再次執行文件就能夠啦
[root@localhost ~]# sh ./test.sh
相關文章
相關標籤/搜索