创建一个bashshell脚本,可以创建PHP程序

Create a bash shell script that can create a PHP program

寻找使 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 文件缺少所有以 $ 开头的变量,你们能帮忙吗?

这里处理引用问题的最简单方法是使用 "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,防止了变量的扩展。