0

以下の例では、todel.txt ファイルに $a=b という行があるはずでした。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
?>
4

2 に答える 2

3

「ヒアドキュメント」を引用符で囲みます。


#!/bin/sh
cat > todel.txt << "heredoc"
<?php
$a=b
# this is comment
?>
heredoc
于 2011-03-10T07:41:49.953 に答える
1

bash(1)マニュアルページから:

のいずれかの文字wordが引用符で囲まれている場合、これdelimiterはの引用符の削除の結果でありword、ヒアドキュメントの行は展開されません。

#!/bin/sh
cat > todel.txt << "heredoc"
<?php
$a=b
# this is comment
?>
heredoc
于 2011-03-10T07:42:56.487 に答える