Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法将变量从php传递到bash_Php_Bash_Shell - Fatal编程技术网

无法将变量从php传递到bash

无法将变量从php传递到bash,php,bash,shell,Php,Bash,Shell,我试图建立一个html表单,将变量传递给php脚本,然后再传递给bash脚本 我能够成功地将变量从html表单传递到php脚本,并且能够将以下传递变量传递到我的bash脚本: <?php shell_exec('./bashscript.sh testarg1 testarg2 testarg3 testarg4'); ?> 这是我第一次尝试从php传递到bash。括号内的参数在没有问题的情况下发布到db。我将如何更改它以成功地将参数传递给bash脚本?thx.变量在双引号字符串中

我试图建立一个html表单,将变量传递给php脚本,然后再传递给bash脚本

我能够成功地将变量从html表单传递到php脚本,并且能够将以下传递变量传递到我的bash脚本:

<?php
shell_exec('./bashscript.sh testarg1 testarg2 testarg3 testarg4');
?>

这是我第一次尝试从php传递到bash。括号内的参数在没有问题的情况下发布到db。我将如何更改它以成功地将参数传递给bash脚本?thx.

变量在双引号字符串中展开,而不是在单引号字符串中展开

shell_exec("./bashscript.sh $_POST[arg1] $_POST[arg2] $_POST[arg3] $_POST[arg4]");
这是基本的PHP语法,与使用shell无关


如果每个参数包含shell元字符,则在替换它之前,还应使用
escape\u shell\u arg
对其进行转义。

正确连接<代码>'./bashscript.sh'.$\u POST['arg1'..'...$\u POST['arg2'..'..'.'.'.'。
[arg1]
[arg2]
[arg3]
[arg4]
shell_exec("./bashscript.sh $_POST[arg1] $_POST[arg2] $_POST[arg3] $_POST[arg4]");