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
2
3
root@debian:/# head -1 /data/deploy/deploy.sh | od -c
0000000 357 273 277 # ! / b i n / s h \n
0000015

发现 #!/bin 前面有数字 357 273 277 这个应该就是文件BOM信息,删掉它就能解决问题了。

1、方法一

1
sed -i '1s/^.*#//;s/\r$//' /data/deploy/deploy.sh

2、方法二
使用dos2unix 命令进行dos脚本转unix

1
2
root@debian:/# dos2unix /data/deploy/deploy.sh
Command 'dos2unix' not found, but can be installed with:

使用 apt-get install dos2unix 进行安装

1
2
root@debian:/# dos2unix /data/deploy/deploy.sh 
dos2unix: converting file /data/deploy/deploy.sh to Unix format...

3、测试

1
2
3
root@debian:/# head -1 /data/deploy/deploy.sh  | od -c
0000000 # ! / b i n / s h \n
0000012

正常了执行shell再也不会提示line 1: #!/bin/sh: No such file or directory