我正在编写一个PHP脚本,我必须在其中运行shell脚本,
我有2个选项:
我用了
shell_exec(dirname(__FILE__) ."/shl.sh");
for execute shell ....现在问题是..如果我在shell中使用#!/ usr / bin / php它只解析<?php ?>
中的代码并直接在屏幕上打印shell语句。
最好的选择(到目前为止!)将修改外部脚本以接受命令行参数。
而不是
shell_exec('sh.sh');
嵌入所有变量的地方,将其变为
shell_exec("./sh.sh $opt1 $opt2");
您可以在哪里轻松传递变量。
使用这些参数的bash脚本的示例是:
#!/bin/bash
echo "My $1 will kick your $2 anytime"
它将用第一个参数替换$ 1,用第二个参数替换$ 2。