如何添加shebang#!与Linux上的PHP脚本? [英] How to add shebang #! with php script on linux?

查看:79
本文介绍了如何添加shebang#!与Linux上的PHP脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在添加shebang#时遇到了一些问题!与我在RedHat linux上的php脚本.我有一小段添加了shebang的测试代码(我也尝试了不同的变体),但是每次尝试运行该脚本时,都会收到以下错误消息.

I'm having a little issue with adding shebang #! with my php script on RedHat linux. I have a small piece of test code with shebang added (I've tried different variations as well), but I get the following error message everytime I try to run the script.

错误消息:

-bash: script.php: command not found

测试脚本:

#!/bin/env php    
<?php echo "test"; ?>

Shebang#!变体:

Shebang #! variations:

#!/usr/bin/php
#!/usr/bin/env php

推荐答案

(对于大多数系统)应该为#!/usr/bin/env php,但您的错误与此无关.

It should (for most systems) be #!/usr/bin/env php, but your error isn't related to that.

-bash: script.php: command not found

它表示未找到 script.php .

如果问题出在shebang行,那么错误将显示为:

If the problem was the shebang line then the error would say something like:

bash: script.php: /usr/env: bad interpreter: No such file or directory

大概是您在键入script.php,并且该文件不在$PATH上的目录中或不可执行.

Presumably, you are typing script.php and the file is not in a directory on your $PATH or is not executable.

  1. 使其可执行:chmod +x script.php.
  2. 键入路径而不是文件名(如果它在当前目录中):./script.php.
  1. Make it executable: chmod +x script.php.
  2. Type the path to it instead of just the filename, if it is in the current directory then: ./script.php.

代替2,您可以将文件移动/复制/符号链接到$PATH

Instead of 2, you can move/copy/symlink the file to somewhere listed in $PATH or modify the $PATH to include the directory containing the script.

这篇关于如何添加shebang#!与Linux上的PHP脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆