I am trying to write a simple CLI script, so I have the following code saved in a file named test.php
#!/usr/bin/php -q
<?php echo "Hello world of PHP CLI!"; ?>
When I try to execute the script by running the command ./test.php
I get the following output
./test.php: line 3: ?php: No such file or directory
Hello world of PHP CLI!
./test.php: line 5: syntax error near unexpected token `newline'
./test.php: line 5: `?>'
where I can see the expected output, but I also get some errors. Why am I seeing these errors and how can I fix this?
php --version
output is
PHP 7.4.3 (cli) (built: Jul 5 2021 15:13:35) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies