LoginSignup
17
19

More than 5 years have passed since last update.

テキストファイルに埋め込んだ環境変数を展開する

Last updated at Posted at 2014-08-11

ご利用は自己責任で。

こんなテキストファイルがあります。

$ cat test.txt
LANG is $LANG
LANG is "$LANG"
LANG is '$LANG'

普通にcatすれば上記の通りですが、これをこうすればヒアドキュメント形式になって……

$ printf "cat <<++EOS\n`cat test.txt`\n++EOS\n"
cat <<++EOS
LANG is $LANG
LANG is "$LANG"
LANG is '$LANG'
++EOS

shに渡せば展開されます。

$ printf "cat <<++EOS\n`cat test.txt`\n++EOS\n" | sh
LANG is ja_JP.UTF-8
LANG is "ja_JP.UTF-8"
LANG is 'ja_JP.UTF-8'

以上。

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