I want to include some HTML in a shell script. This is what I’ve tried:
(
echo "<html>
<head>
<title>HTML E-mail</title>
</head>
<body>
<p style="font-family:verdana;color:red;">
This text is in Verdana and red</p>
</body>
</html>"
)>pkll.htm
However, instead of writing the HTML to file, it gives me some errors:
> bash: color:red: command not found bash: > This text is in Verdana and
> red</p </body> </html>: No such file or directory
How can I do this?
A better option would be to use the here document syntax (see this answer):
Your attempt failed because the double quotes in the HTML terminates the double quotes you wrapped around it and causing the
<>s to be seen as redirections and the;s to terminate theechocommand.You could technically have used single quotes:
but then you just have the same problem again if the HTML contains a
', such as an apostrophe or in an attribute. The here document has no such issues.