CentOS 执行shell脚本报错 $‘\r‘: comma

2023-04-27  本文已影响0人  Rinaloving

错误

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

原因

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

解决方法

  1. 方法1
sed -i 's/\r//' one-more.sh
  1. 方法2
dos2unix one-more.sh
dos2unix: converting file one-more.sh to Unix format ...
-bash: dos2unix: command not found
yum install -y dos2unix
上一篇 下一篇

猜你喜欢

热点阅读