shell 脚本执行报错:”#!/bin/bash: not found”

shell 脚本第1行写的是 #!/bin/bash,执行时却报错 #!/bin/bash: not found ,很是奇怪,请问如何解决?

./deploy-development.sh
./deploy-development.sh: 1: ./deploy-development.sh: #!/bin/bash: not found

回答

是文件编码引起的,出问题的脚本的文件编码是 UTF-8

$ file deploy-development.sh                                                                                                                   
deploy-development.sh: Bourne-Again shell script, UTF-8 Unicode (with BOM) text executable

没这个问题的脚本的文件编码是 ASCII

Bourne-Again shell script, ASCII text executable

将文件编码从 UTF-8 改为 ASCII 问题就解决了。

以上是shell 脚本执行报错:”#!/bin/bash: not found”的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>