Shell programming (seven): $'\r': command not found

1 Overview

Hello everyone, I am Ouyang Fangchao.
The script written on Windows was run on Linux, but the following error occurred:

./startup.sh:行3: $'\r': 未找到命令

2. Reason Analysis

The two operating system platforms have different interpretations of newlines. In Windows, \r\n means newline, while in Linux, \n means newline. Therefore, after the shell file written on Windows is uploaded to Linux, it will fail to recognize \r\n r and report an error. So one of the ways is to replace \r, you can use the following command to operate:

sed -i 's/\r//' test.sh

You can also use the dos2unix command, which has not been tried yet.

3. Summary

The problem recorded today is very simple, but I still write it down, because I always feel that I have encountered this kind of problem before, so I will leave a deep impression this time.
I'm Ouyang Fangchao, and I'm interested in doing things well. If you like my article, please like, forward, comment and pay attention. See you next time.

Guess you like

Origin blog.csdn.net/u012288582/article/details/128459672