Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Bash variable within single and double quote

Given I have the following env variables declared:

MY_VARIABLE_HERE=myValue
SECOND_VARIABLE=secondValue

How can I retrieve these variable within a single quote, wrapped in double quote. i.e. the following

echo '<tag><action name="$MY_VARIABLE_HERE" value="$SECOND_VARIABLE"/></tag>' > my_text.txt

So the expected output for the my_text.txt
would be

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<tag>
  <action name="myValue" value="secondValue" />
</tag>

>Solution :

echo '<tag><action name="'${MY_VARIABLE_HERE}'" value="'${SECOND_VARIABLE}'"/></tag>' > my_text.txt
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading