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.

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

报告相同问题?

悬赏问题

  • ¥15 写一个可直接调用的函数,将32位有符号数转成另一个无符号的数
  • ¥15 CMAKE+VS2019+QT5.15.2组合进行二次编译
  • ¥15 nginx 配置静态html访问 ,后台登录时页面始终被重定向到登录页,无法访问到后台的静态html页
  • ¥20 自动登录的j2ee程序编译
  • ¥15 fluent模拟静态气体扩散
  • ¥15 java根据模板,生成word文档,需要带目录
  • ¥15 广告联盟的兜底广告是什么意思
  • ¥15 如何证明高斯噪声的包络公式
  • ¥150 寻找王者荣耀开发作者,合作或者解答
  • ¥15 关于cpci总线的几个问题,别用人工智能回答