bash 当解释器位于非标准位置时,如何解决“错误解释器”错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17886025/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I solve "bad interpreter" error when interpreter is in non-standard location?
提问by JP Lew
So my first problem is that I'm hosting on GoDaddy.
所以我的第一个问题是我在 GoDaddy 上托管。
Second problem is that when I try to execute the following PHP script via SSH...
第二个问题是,当我尝试通过 SSH 执行以下 PHP 脚本时...
./searchreplacedb2cli.php -h hostname -u username -d databasename -p 'password'
...I get a /usr/bin/php: bad interpreter: No such file or directory
error. This is because on shared hosting, there is no /usr/bin/php
. Instead, the php cli I want is located here:
...我得到一个/usr/bin/php: bad interpreter: No such file or directory
错误。这是因为在共享主机上,没有/usr/bin/php
. 相反,我想要的 php cli 位于此处:
/usr/local/php5_3/bin/php
So, I manually changed the shebang declaration in the script to...
因此,我手动将脚本中的 shebang 声明更改为...
#!/usr/local/php5_3/bin/php -q
...and sure enough, it works.
...果然,它有效。
However, I don't want to have to edit this script manually. I'm looking for a way to circumvent this issue programmatically. I use this script to deploy Wordpress sites on the fly. I wget
it from a git repository each time I use it. Furthermore it is deleted and installed regularly from a bash script, so modifying it in a text editor each time is not an option.
但是,我不想手动编辑此脚本。我正在寻找一种以编程方式规避此问题的方法。我使用此脚本即时部署 Wordpress 站点。wget
每次使用它时,我都会从 git 存储库中获取它。此外,它会定期从 bash 脚本中删除和安装,因此不能每次都在文本编辑器中修改它。
Is there a way to pass an alternate interpreter to a bash command? Like, "if you don't find the default interpreter, use this one instead".
有没有办法将备用解释器传递给 bash 命令?比如,“如果你没有找到默认的解释器,就用这个代替”。
I tried this but it doesn't work:
我试过这个,但它不起作用:
./searchreplacedb2cli.php -h hostname -u username -d databasename -p 'password' | /usr/local/php5_3/bin/php
And because it's shared hosting I lack the permissions to symlink /usr/bin/php to the right place.
而且因为它是共享主机,所以我没有将 /usr/bin/php 符号链接到正确位置的权限。
My next idea was to, via bash, edit line 1 of the php script using a sed
replace command. I thought I would inquire here first for alternatives. Thanks.
我的下一个想法是通过 bash 使用sed
替换命令编辑 php 脚本的第 1 行。我想我会先在这里询问替代方案。谢谢。
回答by Marek
If it's only this host, add /usr/local/php5_3/bin/ to your $PATH, and use this shebang:
如果只有这台主机,请将 /usr/local/php5_3/bin/ 添加到您的 $PATH,并使用此shebang:
#!/usr/bin/env php