25
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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
25
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
25
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?