Linux执行Shell提示No such file or directory
2019年11月14日
line 1: #!/bin/sh: No such file or directory
造成这样的原因,编码格式问题UTF-8 Unicode (with BOM)问题,解决办法就是将文件中 BOM信息删除掉。
Use dos2unix (or sed, tr, awk, perl, python…) to fix your script if this is the issue.Here is one that will remove both of a BOM and tailing CRs:
查看shell脚本头部信息发现
1 | root@debian:/# head -1 /data/deploy/deploy.sh | od -c |
发现 #!/bin 前面有数字 357 273 277 这个应该就是文件BOM信息,删掉它就能解决问题了。
1、方法一
1 | sed -i '1s/^.*#//;s/\r$//' /data/deploy/deploy.sh |
2、方法二
使用dos2unix 命令进行dos脚本转unix
1 | root@debian:/# dos2unix /data/deploy/deploy.sh |
使用 apt-get install dos2unix 进行安装
1 | root@debian:/# dos2unix /data/deploy/deploy.sh |
3、测试
1 | root@debian:/# head -1 /data/deploy/deploy.sh | od -c |
正常了执行shell再也不会提示line 1: #!/bin/sh: No such file or directory