Linux:$‘\r‘: command not found

在Linux系统中,运行Shell脚本,出现了如下错误:

one-more.sh: line 1: $'\r': command not found

出现这样的错误,是因为Shell脚本在Windows系统编写时,每行结尾是\r\n,而在Linux系统中行每行结尾是\n,所以在Linux系统中运行脚本时,会认为\r是一个字符,导致运行错误。

解决方法

去除Shell脚本的\r字符:

方法1

sed -i 's/\r//' one-more.sh

方法2

dos2unix one-more.sh

输出如下:

dos2unix: converting file one-more.sh to Unix format ...

如果出现如下错误:

-bash: dos2unix: command not found

说明dos2unix还没有安装,安装一下即可

猜你喜欢

转载自blog.csdn.net/DragonGirI/article/details/129327308