How to expand shell variables in a text file?

前端 未结 10 1448
夕颜
夕颜 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:28

    This solution is not elegant, but it works. Create a script call shell_expansion.sh:

    echo 'cat <  temp.sh
    cat "$1"                 >> temp.sh
    echo 'END_OF_TEXT'       >> temp.sh
    bash temp.sh >> "$2"
    rm temp.sh
    

    You can then invoke this script as followed:

    bash shell_expansion.sh Text_File.msh Text_File_expanded.msh
    

提交回复
热议问题