/bin/ksh: 错误的解释器:没有那个文件或目录

1 bash ksh shell-script shebang source-command

#!/bin/ksh在第一行有脚本。当我尝试执行此脚本 (run ./myscript.sh) 时发生错误:

-bash: ./myscript.sh: /bin/ksh: bad interpreter: No such file or directory
Run Code Online (Sandbox Code Playgroud)

但是当我通过source myscript.shbash myscript.sh命令执行此脚本时- 脚本成功运行。

是的,没有安装ksh,安装这个是正确的。但我无法理解不同的行为./bashsource

小智 5

  • 当使用./来自 shebang 行的解释器执行脚本时,将调用。

  • 使用source当前的 shell(source是一个 bash 扩展,所以你必须运行 bash)

  • 使用bash script.shshellscript 调用 PATH 中的 bash shell。