Shell腳本出現$'\r': command not found


Centos7下執行shell腳本報錯如下

[root@ip-172-29-10-16 ~]# sh install_zabbix_agent.sh 
install_zabbix_agent.sh: line 2: $'\r': command not found
install_zabbix_agent.sh: line 8: $'\r': command not found
install_zabbix_agent.sh: line 9: $'\r': command not found
install_zabbix_agent.sh: line 10: syntax error near unexpected token `$'{\r''
'nstall_zabbix_agent.sh: line 10: `install_zabbix(){

 

 

原因

這是因為腳本文件可能在window弄過,有window下的空行,把他轉換成unix格式的就行
 

解決辦法

yum install dos2unix

 

然后再執行這個腳本就可以了
 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM