【发布时间】:2016-02-01 19:04:02
【问题描述】:
这是我的工作流程:
ubuntu$ cat test.sh
#!/bin/bash
function getNumber
{
echo 1
}
ubuntu$ cat test.php
<?php
echo shell_exec("getNumber");
ubuntu$ source test.sh
ubuntu$ getNumber
1
ubuntu$ php test.php
sh: 1: getNumber: not found
是否可以改变一个 php 脚本(或者可能是它的调用)的方式,所以它会打印“1”?我正在寻找一种方法来从 php 调用 bash 函数。
我从这里尝试了一些解决方案:Is it possible to source a *.sh file using PHP CLI and access exported Env vars in the PHP script?
其中一个是:./test.sh && php -f test.php - 但没有运气。
【问题讨论】: