如何将程序名称 throgh php 传递给 shell 脚本文件


How can i pass a program name throgh php to a to a shell script file?

通过HTML文件,我将文件名发送到运行shell脚本的位置。我想将该文件名作为参数发送到 shell 脚本。 $prg1=$_POST['prg1'];我从用户输入导入的这个文件。 shell_exec('./shell.sh')在此脚本中,我想发送该文件.有什么帮助吗?

使用 escapeshellarg 添加适当的引号,然后将其作为参数连接到脚本。

shell_exec('./shell.sh ' . escapeshellarg($prg1));

然后,脚本可以将参数获取为$1

对于多个参数,请用空格分隔它们:

shell_exec('./shell.sh ' . escapeshellarg($prg1) . ' ' . escapeshellarg($prg2) . ' ' . escapeshellarg($prg3) );