LoginSignup
0
0

More than 5 years have passed since last update.

ヒアドキュメントのメモ

Last updated at Posted at 2018-10-22

実行結果を見たい場合

cat << 'EOS'
hoge
fuga
`echo aaa`
EOS

ファイルに書き出す場合

cat << 'EOS' > aaa.txt
hoge
fuga
`echo aaa`
EOS

$ cat aaa.txt 
hoge
fuga
`echo aaa`

コマンド部分を実行して書きだす場合(EOSのシングルクォートを外す)

cat << EOS > aaa.txt
hoge
fuga
`echo aaa`
EOS

$ cat aaa.txt 
hoge
fuga
aaa

亜種(こんなのもあるょ)

tee /tmp/bbb/aaa.txt <<'EOS' >/dev/null
hoge
fuga
`echo aaa`
EOS

ひとこと


  • シングルクォートの有り無しで挙動が変わるので注意。
  • EOSの部分は、なんでもよい。KOF(キングオブファイターズ)とかどうだろうか?

dockerfileなどでよく見かけるし、いろいろと便利に使えると思う。

0
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
0
0