2
0

ヒアドキュメント内で変数を展開しない方法

Last updated at Posted at 2023-08-20

以下のEOTを" or ' でくくると展開されない

#!/bin/bash

MSG1="HELLO WORLD.(test1)"
MSG2="HELLO WORLD.(test2)"
MSG3="HELLO WORLD.(test3)"

echo "here document test 1."
cat << EOT # $MSG1展開される
<HTML>
<BODY>
$MSG1
</BODY>
</HTML>
EOT

echo "here document test 2."
cat << 'EOT' # $MSG2展開されない
<html>
<body>
$MSG2
</body>
</html>
EOT

echo "here document test 3."
cat << "EOT" # $MSG3展開されない
<html>
<body>
$MSG3
</body>
</html>
EOT

参考

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0