创建一个可以创建PHP程序的bash shell脚本

时间:2017-09-25 16:25:17

标签: php bash sh tee

寻找能够自动执行bash脚本获取.PHP程序内容的能力,并在权限为755的特定目录中创建它。我基本上想给用户这个.sh脚本安装适当的程序和文件以启动并运行网站。我遇到的问题是PHP变量不会保存在输出文件中。我使用以下命令:

echo "<?php
header('Content-Type: text/xml');
require_once '/var/www/osbs/PHPAPI/account.php';
require_once '/var/www/osbs/zang/library/Zang.php';
$To = $_POST['subject'];
$Body = $_POST['text'];
# If you want the response decoded into an Array instead of an Object, set 
response_to_array to TRUE, otherwise, leave it as-is
$response_to_array = false;
# Now what we need to do is instantiate the library and set the required 
options defined above
$zang = Zang::getInstance();
# This is the best approach to setting multiple options recursively Take note that you cannot set non-existing options
$zang -> setOptions(array(
'account_sid' => $account_sid,
'auth_token' => $auth_token,
'response_to_array' => $response_to_array ));
?>" | tee /var/www/output.php

output.php文件缺少所有以$开头的变量你们可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

此处处理引用问题的最简单方法是使用"here-doc"

cat >/var/www/output.php <<"EOF"
<?php
header('Content-Type: text/xml');
require_once '/var/www/osbs/PHPAPI/account.php';
require_once '/var/www/osbs/zang/library/Zang.php';
$To = $_POST['subject'];
$Body = $_POST['text'];
# If you want the response decoded into an Array instead of an Object,
# set response_to_array to TRUE, otherwise, leave it as-is
$response_to_array = false;
# Now what we need to do is instantiate the library and set the
# required options defined above
$zang = Zang::getInstance();
# This is the best approach to setting multiple options recursively.
# Take note that you cannot set non-existing options
$zang -> setOptions(array(
'account_sid' => $account_sid,
'auth_token' => $auth_token,
'response_to_array' => $response_to_array ));
?>
EOF

不需要tee(除非你真的想将所有内容转储到控制台,这似乎是不必要的)。引用分隔符字符串(<<"EOF")会有效地引用整个here-doc,从而阻止变量的扩展。