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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵