今天在运行项目的时候,我运行XXX.sh的时候总是出现这个错误,后来我通过“$‘\r‘: command not found的解决方法_万猫学社的博客-CSDN博客”这个去找答案,但是还是不行,我以为是本地linux(WSL)的缺陷问题,然后我租了个服务器再次尝试,发现还是一样的,最后才看到原来是这个sh里面的运行其他的sh出现了问题,要对sh中包含的所有的sh文件进行处理,而我只处理了一个
解释:
在Linux系统中,运行Shell脚本,出现了如下错误:one-more.sh: line 1: $'\r': command not found
备注:如果dos2unix: command not found,直接按照他们的提示按照就可以了:yum install -y dos2unix
运行好出现:
dos2unix: converting file one-more.sh to Unix format ...
说明成功去除字符
2、重新运行该sh文件:
bash XXX.sh
成功!
解决方法二:
由于方法一还安装dos2unix,所以还有别的办法
去除Shell脚本的\r字符:
sed -i 's/\r//' XXXX.sh
情况二:Linux脚本执行出现"%0D"的问题
mv: cannot stat 'ckpt_epoch_240.pth': No such file or directory : not foundch_pretrained_teachers.sh: 26: scripts/fetch_pretrained_teachers.sh: --2023-04-05 13:55:35-- http://shape2prog.csail.mit.edu/repo/ResNet50_vanilla/ckpt_epoch_240.pth%0D Resolving shape2prog.csail.mit.edu (shape2prog.csail.mit.edu)... 198.18.3.214 Connecting to shape2prog.csail.mit.edu (shape2prog.csail.mit.edu)|198.18.3.214|:80... connected. HTTP request sent, awaiting response... 404 Not Found 2023-04-05 13:55:36 ERROR 404: Not Found.