從windows上傳了一個腳本到linux上執行 出現如下錯誤:$’\r’: command not found
[root@izw server-cocos]# bash start.sh
start.sh: line 2: $'\r': command not found
通過錯誤信息知道無法執行\r. ,確定寫腳本時沒有加入這個字符 。這可能是格式問題造成。
這是windows與Unix文本編輯的默認格式不同造成的 ,需要轉成unix格式
[root@izw server-cocos]# dos2unix start.sh
-bash: dos2unix: command not found
這是因爲沒有安裝dos2unix
於是在linux下安裝了dos2unix
使用yum安裝:
yum -y install dos2unix*
修改格式
$ dos2unix 腳本名
[root@izw server-cocos]# dos2unix start.sh
dos2unix: converting file start.sh to Unix format ...
再次運行shell腳本,即可成功
…