代码唯一的不同就是第二次使用了一个变量“$myVar”,试试运行,PHP竟然给出出错的信息:“Parse error: parse error in - on line 2”!这是因为Bash中的变量也是“$myVar”,而Bash解析器先将变量给替换掉了,要想解决这个问题,你需要在每个PHP的变量前面加上“\”转义符,那么刚才的代码修改如下:
#!/bin/bash
echo This is the Bash section of the code.
/usr/local/bin/php -q << EOF
<?php
\$myVar = 'PHP';
print("This is the \$myVar section of the code\n");
?>
EOF
好了,现在你可以用PHP编写你自己的Shell脚本了,希望你一切顺利。如果有什么问题,可以去http://www.PHPBuilder.com或者http://www.zPHP.com上面讨论。
#!/bin/bash
echo This is the Bash section of the code.
/usr/local/bin/php -q << EOF
<?php
\$myVar = 'PHP';
print("This is the \$myVar section of the code\n");
?>
EOF
好了,现在你可以用PHP编写你自己的Shell脚本了,希望你一切顺利。如果有什么问题,可以去http://www.PHPBuilder.com或者http://www.zPHP.com上面讨论。
| 对此文章发表了评论 |
