linux bash and html variables (import and export)

2019-09-20 18:42发布

问题:

I've something like:

var1=name
var2=surname

I need export these variables and import it to html file

any idea?

回答1:

echo "<html><body>" > index.html
echo "var1 is $var1 <br>" >> index.html
echo "var2 is $var2 <br>" >> index.html
echo "</body></html>" >> index.html


回答2:

For a simplistic form of templating, you can do

var1=name
var2=surname

cat > somefile.html << EOF
  <title>$var1's demo page!</title>
  <body>
    Hello, $var1 $var2. 
  </body>
EOF


标签: html linux bash