How to expand shell variables in a text file?

前端 未结 10 1445
夕颜
夕颜 2021-02-04 02:05

Consider a ASCII text file (lets say it contains code of a non-shell scripting language):

Text_File.msh:

spool on to \'$LOG_FILE_PATH/lo         


        
10条回答
  •  孤城傲影
    2021-02-04 02:31

    This question has been asked in another thread, and this is the best answer IMO:

    export LOG_FILE_PATH=/expanded/path/of/the/log/file/../logfile.log
    cat Text_File.msh | envsubst > Text_File_expanded.msh
    

    if on Mac, install gettext first: brew install gettext

    see: Forcing bash to expand variables in a string loaded from a file

提交回复
热议问题