2

How do we create html file in shell script?

I tried the below code

    echo "<html>"
    echo "<head>"
    echo "<style type=\"text/css\">"
    echo "table{background-color:#DCDCDC}"
    echo "thead {color:#708090}"
    echo "tbody {color:#191970}"
    echo "</style>"
    echo "</head>"
    echo "<body>"
    echo "<table border=\"1\">"
    echo "<thead>"
    echo "<tr width="100" bgcolor='#C0C0C0'><center><td colspan="3"><font color="#000000"><b>CONSOLIDATED RUNBOOK</b></font></center></td>"
    echo "</h4>"
    echo "</tr>"
    echo "<tr>"
    echo "<th><col width="100"><font color="000000">APP NAME</font></th>"
    echo "<th><col width="100"><font color="000000">STATUS</font></th>"
    echo "<th><col width="100"><font color="000000">STATUS AS ON</font></th>"
    echo "</tr>"
 >> text.html

I am trying to create html file with the help of shell script. Can you please help>

3
  • 2
    If you're using " for your echo statements you can't use " within the string unless you escape each instance with backslash \ Why not use some kind of template system instead of this dizzying pile of echo statements? Using something primitive like sed would be better than this. Commented May 14, 2018 at 17:34
  • 1
    Or a here document. Commented May 14, 2018 at 17:42
  • Possible duplicate of Open and write data on text file by bash/shell scripting Commented May 14, 2018 at 17:42

2 Answers 2

1
{
echo "<html>"
echo "<head>"
echo "<style type=\"text/css\">"
echo "table{background-color:#DCDCDC}"
echo "thead {color:#708090}"
echo "tbody {color:#191970}"
echo "</style>"
echo "</head>"
echo "<body>"
echo "<table border=\"1\">"
echo "<thead>"
echo "<tr width="100" bgcolor='#C0C0C0'><center><td colspan="3"><font color="#000000"><b>CONSOLIDATED RUNBOOK</b></font></center></td>"
echo "</h4>"
echo "</tr>"
echo "<tr>"
echo "<th><col width="100"><font color="000000">APP NAME</font></th>"
echo "<th><col width="100"><font color="000000">STATUS</font></th>"
echo "<th><col width="100"><font color="000000">STATUS AS ON</font></th>"
echo "</tr>"
}>> text.html
Sign up to request clarification or add additional context in comments.

1 Comment

That doesn't fix the quoting issue.
1

You could use a heredoc instead:

cat > text.html <<EOF
<html>
<head>
<style type=\"text/css\">
table{background-color:#DCDCDC}
thead {color:#708090}
tbody {color:#191970}
</style>
</head>
<body>
<table border=\"1\">
<thead>
<tr width="100" bgcolor='#C0C0C0'><center><td colspan="3"><font color="#000000"><b>CONSOLIDATED RUNBOOK</b></font></center></td>
</h4>
</tr>
<tr>
<th><col width="100"><font color="000000">APP NAME</font></th>
<th><col width="100"><font color="000000">STATUS</font></th>
<th><col width="100"><font color="000000">STATUS AS ON</font></th>
</tr>
EOF

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.