Search code examples
bashenvironment-variablesechocat

echo the cat content into a file


I have file "setting.xml" which contains some environment variable

<localRepository>/Users/$(whoami)/.m2/repository

I want to write the content of setting.xml into production.xml and replace the $(whomai) with my userid

I tried below

cat setting.xml | echo > production.xml

but not sure how can I pass the content to my echo command


Solution

  • You can try:

    sed "s/\$(whoami)/$(whoami)/" < setting.xml >production.xml
    

    The sed is an stream editor, and in the above, replaces the literal $(whoami) with the result of the command whoami.