【问题标题】:pre processed here doc在这里预处理文档
【发布时间】:2011-07-12 12:31:24
【问题描述】:

在下面给出的示例中,我期待这条线 $a=b 在 todel.txt 文件中。 如何在不处理的情况下添加 here doc 文本块?

[root@localhost]# cat here_example.sh 
#!/bin/sh
cat > todel.txt << heredoc
<?php
$a=b
# this is comment
?>
heredoc

[root@localhost]# cat todel.txt 
<?php
=b
# this is comment
?>

【问题讨论】:

    标签: heredoc cat shell


    【解决方案1】:

    在“heredoc”周围加上引号:

    
    #!/bin/sh
    cat > todel.txt << "heredoc"
    <?php
    $a=b
    # this is comment
    ?>
    heredoc
    

    【讨论】:

      【解决方案2】:

      来自bash(1) 手册页:

      如果word 中的任何字符是 引用,delimiter 是在 word 上删除引用的结果,并且 here-document 中的行不展开。

      #!/bin/sh
      cat > todel.txt << "heredoc"
      <?php
      $a=b
      # this is comment
      ?>
      heredoc
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-10
        • 1970-01-01
        • 2020-02-03
        • 2014-09-25
        • 2012-09-03
        • 2013-09-01
        • 2011-08-07
        相关资源
        最近更新 更多