Using Sed to expand environment variables inside files

后端 未结 2 1700
余生分开走
余生分开走 2020-12-21 05:38

I\'d like to use Sed to expand variables inside a file.

Suppose I exported a variable VARIABLE=something, and have a \"test\" file with the following:



        
2条回答
  •  离开以前
    2020-12-21 06:22

    Maybe you can get by without using sed:

    $ echo $VARIABLE
    something
    $ cat test
    I'd like to expand this: ${VARIABLE}
    $ eval "echo \"`cat test`\"" > outputfile
    $ cat outputfile
    I'd like to expand this: something
    

    Let shell variable interpolation do the work.

提交回复
热议问题