sandy
sandy

Reputation: 1158

Pass variable on shell

I am running the exec command in PHP. I need to pass the variables along with it.

exec(sh myfilename.sh);

how can i pass variables to the above command ?

Upvotes: 0

Views: 55

Answers (2)

Alma Do
Alma Do

Reputation: 37365

You can do it with

exec(escapeshellarg('/bin/sh myfilename.sh '.$key0.'='.$value0)); //e t.c.

-but to get that values, you should work with bash shell language (i.e. receive in myfilename.sh). See this article about that. In SO, there is a great answer about that - see here.

Upvotes: 2

Gar
Gar

Reputation: 862

$v1="abc=cde";
$v2="fgh=ijk";
$v3="lmn=opq";
exec("sh myfilename.sh $v1 $v2 $v3");

Upvotes: -1

Related Questions