[英]Running php script from shell does not echo anything
I have a very simple test.php file: 我有一个非常简单的test.php文件:
<?php
echo 'Hello World';
Then I run it from Mac Shell: php test.php
But it does not echo anything. 然后,我从Mac Shell运行它:
php test.php
但它没有回显任何内容。 Looks like it's blocked for some reason, like this: 似乎由于某种原因被阻止,如下所示:
If I use invalid syntax in the file, for example: 如果我在文件中使用了无效的语法,例如:
<?php
invalid syntax
Then I can see the error output: 然后我可以看到错误输出:
PHP Parse error: syntax error, unexpected 'syntax' (T_STRING) in .../test.php on line 3
Parse error: syntax error, unexpected 'syntax' (T_STRING) in .../test.php on line 3
What's wrong with it? 它出什么问题了?
FYI: 供参考:
php -i
can print php.ini info php -i
可以打印php.ini信息 echo 'test'
can print 'test' echo 'test'
可以打印'test' Turning my comments into an answer as requested : 根据 要求将我的评论变成答案:
Here are two possible reasons why php command doesn't work as expected: 这是php命令无法按预期运行的两个可能原因:
Maybe it is aliased (try which php
or prepend a backslash (\\) to the command) 也许是别名(尝试在该命令中使用
which php
或在其前面加上反斜杠(\\) )
You mentioned that you had a directory named php on your working directory. 您提到您的工作目录上有一个名为php的目录。 Well, zsh has a feature called AUTO_CD that may have interfered in this case.
好吧, zsh具有一个称为AUTO_CD的功能,在这种情况下可能会造成干扰。 Basically AUTO_CD allows you to switch directories without typing cd and can be disabled by adding
unsetopt autocd
to zshrc file. 基本上, AUTO_CD允许您在不键入cd的情况下切换目录,可以通过将
unsetopt autocd
添加到zshrc文件来禁用它 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.