2
1

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

テキスト中のシェル変数を展開したいときにどうするか?

例えば次のような test.txt があって、このなかの NAME と HOGE を展開したい。

% cat test.txt

hello world
${NAME}
${HOGE}

この場合は次のように eval を使えばいい

% export NAME=hoge
% export HOGE=huge
% cat test.txt | while read line; do eval "echo `echo $line`"; done
hello world
hoge
huge

もっと他にいい手段はあるかもしれない。というより、あったらぜひ教えて欲しいです。

2
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?