LoginSignup
24
19

More than 5 years have passed since last update.

ヒアストリングとヒアドキュメント

Posted at

ヒアストリング

変数を擬似的にファイルのように取り扱える ※ bash依存
echo 変数 | command の代替になれる。

sample_herestring
ipaddr="192.0.2.4"
cut -d. -f1-3 <<< ${ipaddr}
output
192.0.2

ヒアドキュメント

複数行をコマンドに渡したり、出力したりできる

コマンドに渡す

$ sendmail -t << EOT
> From: foo@example.com
> To: bar@example.com
> Subject: test
>
> test
> EOT
$

複数行の出力

hoge="foo"
fuga="bar"

cat << EOF
1st ${foo}
2nd ${bar}
EOF
24
19
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
24
19