Fill placeholders in file in single pass

前端 未结 5 1751
旧时难觅i
旧时难觅i 2021-02-09 23:11

I have a skeleton text file with placeholder strings:

blah blah blah
blah $PLACEHOLDER_1$
blah
$PLACEHOLDER_2$

and so on. Specific \"form\" of

5条回答
  •  日久生厌
    2021-02-09 23:33

    I just stumbled upon this question because I was just looking for the exact same, and I found envsubst(1).

    You can use envsubst if you don't mind using environment variables:

    PLACEHOLDER_1='string 1' PLACEHOLDER_2='multiline 
    string 
    2' envsubst < output.template 
    

    If you have a lot of variables you can store them in a file and just source it (remember to use export at the end of the sourced file!)

提交回复
热议问题