运行Bash脚本会导致“错误的解释器:没有此类文件或目录”错误

时间:2021-02-01 00:03:18

I did found questions on

我确实发现了问题

Bad interpreter: No such file or directory thing on SO.

错误的解释器:SO上没有这样的文件或目录。

My issue is also solved when I changed the script from

当我更改脚本时,我的问题也解决了

#!/usr/bin/bash
echo -e "\t\t\e[92mHello from the Test Script!\e[39m"

to:

#!/bin/bash
echo -e "\t\t\e[92mHello from the Test Script!\e[39m"

after I did the first line change from looking an answer here.

在我从这里找到答案后做了第一线改变之后。

Shell script: Bad interpreter.No such file or directory

Shell脚本:错误的解释器。没有这样的文件或目录

I can not understand why removing the /usr from the first line helps.

我无法理解为什么从第一行删除/ usr会有所帮助。

P.S.I am learning about linux file permissions and I was unable to execute my file even after changing the permission using '755'. So, please if anyone can explain me this.Thanks in advance.:)

P.S.I我正在学习linux文件权限,即使在使用'755'更改权限后我也无法执行我的文件。所以,如果有人能解释我的话,请提前。谢谢。:)

4 个解决方案

#1


2  

On your system, the bash shell lives in /bin/bash and not /usr/bin/bash.

在你的系统上,bash shell位于/ bin / bash而不是/ usr / bin / bash。

The path after the ! should be the path to an executable that will be passed the contents of the script as an argument.

之后的路径!应该是可执行文件的路径,该可执行文件将作为参数传递脚本的内容。

You can read more about this at wikipedia

您可以在*上阅读更多相关信息

As for the second part of your question; it would not have mattered what the permissions are; as the file was pointing to a bad interpreter.

至于你问题的第二部分;它不重要的是权限是什么;因为文件指向一个糟糕的解释器。

For more on unix file permissions, I suggest reading this entry on wikipedia.

有关unix文件权限的更多信息,我建议您在*上阅读此条目。

#2


1  

That's because there is no bash binary at /usr/bin/bash and the correct path for bash is /bin/bash.

那是因为/ usr / bin / bash中没有bash二进制文件,而bash的正确路径是/ bin / bash。

The #! line at the top of scripts, called the shebang, determines what program (sh, bash, ruby, perl, python, etc.) is used for running the script.

#!脚本顶部的行,称为shebang,确定用于运行脚本的程序(sh,bash,ruby,perl,python等)。

This post covers this topic well:

这篇文章很好地介绍了这个主题

https://unix.stackexchange.com/questions/87560/does-the-shebang-determine-the-shell-which-runs-the-script

#3


1  

In my case adding sh before script name solved the issue.

在我的情况下,在脚本名称之前添加sh解决了问题。

#4


0  

You can also call your script by adding "./" at the beginning in case you call it from the local directory. The other solution is to call it by specifying its full path.

您也可以通过在开头添加“./”来调用脚本,以防您从本地目录中调用它。另一种解决方案是通过指定其完整路径来调用它。

#1


2  

On your system, the bash shell lives in /bin/bash and not /usr/bin/bash.

在你的系统上,bash shell位于/ bin / bash而不是/ usr / bin / bash。

The path after the ! should be the path to an executable that will be passed the contents of the script as an argument.

之后的路径!应该是可执行文件的路径,该可执行文件将作为参数传递脚本的内容。

You can read more about this at wikipedia

您可以在*上阅读更多相关信息

As for the second part of your question; it would not have mattered what the permissions are; as the file was pointing to a bad interpreter.

至于你问题的第二部分;它不重要的是权限是什么;因为文件指向一个糟糕的解释器。

For more on unix file permissions, I suggest reading this entry on wikipedia.

有关unix文件权限的更多信息,我建议您在*上阅读此条目。

#2


1  

That's because there is no bash binary at /usr/bin/bash and the correct path for bash is /bin/bash.

那是因为/ usr / bin / bash中没有bash二进制文件,而bash的正确路径是/ bin / bash。

The #! line at the top of scripts, called the shebang, determines what program (sh, bash, ruby, perl, python, etc.) is used for running the script.

#!脚本顶部的行,称为shebang,确定用于运行脚本的程序(sh,bash,ruby,perl,python等)。

This post covers this topic well:

这篇文章很好地介绍了这个主题

https://unix.stackexchange.com/questions/87560/does-the-shebang-determine-the-shell-which-runs-the-script

#3


1  

In my case adding sh before script name solved the issue.

在我的情况下,在脚本名称之前添加sh解决了问题。

#4


0  

You can also call your script by adding "./" at the beginning in case you call it from the local directory. The other solution is to call it by specifying its full path.

您也可以通过在开头添加“./”来调用脚本,以防您从本地目录中调用它。另一种解决方案是通过指定其完整路径来调用它。