2011-03-10 67 views
0

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

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

[[email protected]]# cat todel.txt 
<?php 
=b 
# this is comment 
?> 

回答

3

戴上引号 “定界符”:


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

请参阅Bash联机帮助页上的“Here Documents”。 –

1

bash(1)手册页:

如果word任何字符 引用,该delimiter是引用删除的结果在word和 线在这里文件不扩大。

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