Here I am showing you how can you pass the random variable to shell script. ( i.e like $uname 🙂 )
You can receive data using $1 or $2 variable but you can’t directly receive data into $uname or any random variable.
Here is my bash file demo.sh
#!/bin/bash
echo $uname
Now I have to pass $uname variable so directly using this php function you cant do this
exec("sh demo.sh harshkothari",$output);
You have to send it via environment variable . This is simple code snippet how you can you pass this. php file name is shell.php
$uname = 'harshkothari';
putenv('uname='. $uname); //put environment variable uname
exec("sh demo.sh",$output); //execute command
echo($output[0]. "\n"); //print return value
$output will return the last line of output and it will show like this
Harshs-MacBook-Pro:lcmapiuse harshkothari$ php shell.php
harshkothari
Harshs-MacBook-Pro:lcmapiuse harshkothari$
Here is snapshot of terminal output