0

I want to call a php script inside shell script and need to send 4 parameters.I called that called that inside shellscript like this.

php /var/www/php/myscript.php $var1 $var2 $var3 $var4

but php script didn't execute. so what is the correct way to send parameters to php script and execute script inside shellscript?

0

2 Answers 2

0

Suppose you have an executable file file.sh:

#!/usr/bin/php
<?php

include('your/file.php');
exit;

or with the current environment

#!/usr/bin/env php
<?php

include('your/file.php');
exit;

Then execute it on the command line with

$ ./file.sh
Sign up to request clarification or add additional context in comments.

1 Comment

Dont forget to add the right permissions to the file if you want to execute it by issue "./file.sh" for example chmod +x file.sh
0

This is sample, pay special attention to the quotes in the parameters to wrap any character in the string like spaces or dashes that can affect the args reading.

bash.sh

#!/bin/bash
php test.php "$1" "$2"

test.php

<?php

$a = $argv[1];
$b = $argv[2];

echo "arg1 : $a, arg2: $b";

Some Outputs

$bash bash.sh Hello World
arg1 : Hello, arg2: World

$bash bash.sh Hello
arg1 : Hello, arg2:

$bash bash.sh "Hello World"
arg1 : Hello World, arg2:

Hope this helps

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.