1. Problems
When executing the script deploy.sh in CentOS, an error $'\r': command not found is reported.
Reason : The shell script is written under Windows and transferred to CentOS through tool software. However, the ending symbol of the Windows downlink is \r\n , and the end of the Linux downlink is \n . The two are different, so they cannot be recognized and need to be converted.
Two, solve
//执行sh deploy.sh base,报错$'\r': command not found
sh deploy.sh base
//1、dos2unix 脚本名,此处是dos2unix deploy.sh
//如果执行dos2unix deploy.sh报-bash:dos2unix:command not found,就使用yum install -y dos2unix 安装dos2unix
//如果执行成功,会报一个dos2unix: converting file deploy.sh to Unix format ...
dos2unix deploy.sh
//2、安装dos2unix
yum install -y dos2unix
//3、再次执行dos2unix deploy.sh命令
//如果dos2unix deploy.sh执行成功,会报一个dos2unix: converting file deploy.sh to Unix format ...
//如果dos2unix deploy.sh执行成功后,再次执行sh deploy.sh base还不行,依旧报 $'\r': command not found,就执行下面的sed命令
//4、sed -i 's/\r//' 脚本名
sed -i 's/\r//' deploy.sh
//5、再次执行sh deploy.sh base
sh deploy.sh base
After the above dos2unix deploy.sh and sed -i 's/\r//' deploy.sh are executed successfully, execute sh deploy.sh base again (here corresponds to the above 5, execute sh deploy.sh base again ) to start executing the script Commands, pull, build, running, create images and containers.
3. References
$'\r': command not found solution
Shell script execution error $'\r': command not found
Executing Shell script under Linux appears $'\r': command not found solution