0

I have a bash .sh file where I want to call a function located inside of a .php script file, and store the php response in a bash variable.

So far in my bash

#!/bin/bash
/usr/bin/php checkVer.php

Which will run checkVer.php but I want it to run only a particular function.

So I try

#!/bin/bash
PHP_OUT=`php -r 'echo phpinfo();'`
echo $PHP_OUT;

but how does bash know the function phpinfo() is from my .php file?

whatitis2
  • 137
  • 1
  • 3
  • There is no return value from [`phpinfo`](https://www.php.net/manual/en/function.phpinfo.php), ... well, apart from bool! – Dharman Apr 10 '19 at 20:59
  • I do not understand your question. Is `phpinfo()` just an example, or part of the question? Do you want to call a specific userland function which you have saved in a file on a disk? – Dharman Apr 10 '19 at 21:02
  • I want to know how to write bash script so that it will call a php script and then the php script will have a function with a return that will return a 1 or 0 or a string and store that return as a bash variable so I can use it in the bash script. – whatitis2 Apr 10 '19 at 21:12
  • This question has already an answer, be more specific. [How to set a variable to the output of a command in Bash?](https://stackoverflow.com/questions/4651437/how-to-set-a-variable-to-the-output-of-a-command-in-bash) – Dharman Apr 10 '19 at 21:16

0 Answers0