0

I am looking to call a shell script from php and pass input parameters .i am not prolific with php ,but i tried using shell_exec function ,still not able to .

<?php
$a = "www.google.com";
echo shell_exec('sh test9.sh' , "$a");
?>

shell file is

#!/bin/sh
echo $a
2
  • The text inside your shell_exec will be sh test9.shwww.google.com. Might want to make sure you include a space in there. Commented Dec 15, 2015 at 21:00
  • are you using eclipse? Commented Dec 15, 2015 at 21:00

2 Answers 2

1

PHP's shell_exec does not accept variadic arguments; you'll need to pass one string argument with the entire shell statement.

echo shell_exec("sh test9.sh '$a'");

Furthermore, if $a containts untrusted content (like user input), do absolutely never ever forget to escape the value using the escapeshellarg function. Otherwise you'll be vulnerable to shell injection attacks.

Sign up to request clarification or add additional context in comments.

Comments

0

Thing you have to do

 echo shell_exec('sh test9.sh www.google.com');

and in sh script then

 echo $1

read about linux "sh" command , maybe you have to use the absolutpath of the sh "/a/b/c/d.sh" without the sh before the path

shell_exec has no second parameter

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.