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.

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

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!