Bootstrap

Jenkins执行bash脚本提示#!/bin/bash不存在

Jenkins job执行test.sh时日志有打印#!/bin/bash: No such file or directory,/bin/bash显然存在且没有权限问题,日志打印很奇怪。

查看test.sh脚本属性,发现一些端倪:

test.sh: Bourne-Again shell script, UTF-8 Unicode (with BOM) text executable

可以看到test.sh脚本的编码格式是带BOM的UTF-8。修改脚本编码格式去掉BOM:

# vi test.sh

#!/bin/bash
echo "hello,world!"

:set nobomb

:wq

重新查看脚本的属性,已经没有BOM了:

# file test.sh
test.sh: Bourne-Again shell script, ASCII text executable

再次执行job,日志打印恢复正常。

;