简体   繁体   English

如何在bash中为php命令传递变量

[英]How to pass variable in bash for php command

On bash funcion I need pass varible por a external command (php) 在bash函数上,我需要通过外部命令(php)传递变量

panel=$(php -r '$ini_array = parse_ini_file("/root/.name/name.ini");echo $ini_array['panel'];')

Work properly. 好好工作。

But I need pass path on variable and key of array also. 但是我还需要在数组的变量和键上传递路径。 Try several form but all fails. 尝试几种形式,但都失败了。 '', "", ... ”,“”,...

php -r '$ini_array = parse_ini_file(`$sPath`);echo $ini_array["$sKey"];'

It's possible? 这是可能的?

Pass the variable through the environment, and retrieve it from the environment on the PHP side. 在环境中传递变量,然后在PHP端从环境中检索它。

sPath=$sPath sKey=$sKey \
  php -r '$ini_array = parse_ini_file($_ENV["sPath"]);echo $ini_array[$_ENV["sKey"]];'

The initial sPath=$sPath and sKey=$sKey are not necessary if you have used export to put your shell variables in the environment already. 如果已经使用export将shell变量放置在环境中,则不需要初始sPath=$sPathsKey=$sKey

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM