How to Use Bash $Variable Inside Cat

How to Use Bash $Variable Inside Cat

I am faceing an issue when I want to use variable inside cat <<EOF > Test.html , for example

cat <<EOF > Test.html
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<head>
<style type="text/css">

*/:root{--blue:#007


etc ..

Then 

<!-- Heading -->

<span class="h2 mb-0">

 $Test

</span>

</div>

   
etc ..
                
EOF
      

The $Test is not active I mean Bash considered it as a string not variable ( please find attached file )

variable $Test in brown color

1

1 Answer

You have to add escape as shown below:

cat <<\EOF > Test.html
echo $var
EOF

Check the output by cat Test.html.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Maya Lin-Takahashi
Author

Maya Lin-Takahashi

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.