简体   繁体   English

将变量从php传递到shell脚本

[英]Passing of variable from php to shell script

Here's my php code: 这是我的PHP代码:

<?php
$var1="hello.txt";
exec("expect /home/foo.sh $var1");
?>

and my shell script: 和我的shell脚本:

spawn su -s /bin/bash root -c "/usr/bin/gpg --output /home/$1.gpg --encrypt --recipient sampleonly@yahoo.com  /home/$1"
expect "Password:"
send "mypassword\r"
expect "*complete*"

It doesn't get my variable 它没有得到我的变量

You have to assign your arguments to variables like this: 您必须将参数分配给以下变量:

Shell Script: Shell脚本:

set name [lrange $argv 0 0]
send -- "Hello $name"

Terminal command: 终端命令:

expect hello.sh Benjamin

Result: 结果:

Hello Benjamin

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM