doujie7497 2017-09-25 16:25
浏览 115
已采纳

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

Looking for the ability to automate the ability for a bash script to take the contents of a .PHP program and create it in a specific directory with permissions of 755. I basically want to give the user this one .sh script that will install the appropriate programs and files to get a website up and running. The problem I'm running into is the PHP variables won't save in the output file. I'm using the following command:

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

The output.php file is missing all the variables that start with $ can you guys help?

  • 写回答

1条回答 默认 最新

  • droirqk4795 2017-09-25 16:29
    关注

    The easiest way to handle the quoting issues here is to use a "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
    

    There is no need for tee (unless you really want to dump all that stuff to the console, which seems unnecessary). Quoting the delimiter string (<<"EOF") effectively quotes the entire here-doc, preventing the expansion of variables.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效