![](/img/trans.png)
[英]Boto3 Cli: How to pass the variable content in USERDATA to php script?
[英]How to pass bash script variable value in PHP command (CLI)
在傳遞Linux bash-script變量以執行PHP CLI命令時,我需要幫助。
我正在研究執行PHP CLI命令的bash腳本,該命令從bash腳本(如文件夾路徑)獲取輸入變量,以包括用於訪問PHP文件類的文件。
但是在執行bash腳本時發生的是,傳遞給PHP CLI命令的變量充當PHP的變量。
下面是我的腳本的示例代碼
file="$folderpath"somefile.php
mage_version=$(php -r 'include "$file";print_r(Mage::getVersionInfo());')
以下是我得到的錯誤
PHP Notice: Undefined variable: file in Command line code on line 1
PHP Warning: include(): Filename cannot be empty in Command line code on line 1
Bash需要雙引號( "
)來解析變量,否則它們將保持$var
,因此php將讀取它們;
file="$folderpath"somefile.php
mage_version=$(php -r "include \"${file}\";print_r(Mage::getVersionInfo());")
如果您需要多行解決方案,則可以執行以下操作: 在Bash中運行PHP函數(並將返回值保留在bash變量中)
php_cwd=`/usr/bin/php << 'EOF'
<?php echo getcwd(); ?>
EOF`
echo "$php_cwd" # Or do something else with it
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.