Mouhong Lin
Mouhong Lin

Reputation: 4509

Running php script from shell does not echo anything

I have a very simple test.php file:

<?php

echo 'Hello World';

Then I run it from Mac Shell: php test.php But it does not echo anything. Looks like it's blocked for some reason, like this:

Running php script from shell shows nothing

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:

Upvotes: 1

Views: 1913

Answers (1)

fardjad
fardjad

Reputation: 20424

Turning my comments into an answer as requested:

Here are two possible reasons why php command doesn't work as expected:

  1. Maybe it is aliased (try which php or prepend a backslash (\) to the command)

  2. You mentioned that you had a directory named php on your working directory. Well, zsh has a feature called AUTO_CD that may have interfered in this case. Basically AUTO_CD allows you to switch directories without typing cd and can be disabled by adding unsetopt autocd to file.

Upvotes: 1

Related Questions