Create a HTML Document using shell script in Linux

You can actually create a HTML document using the shell script. If you are tired to see the output of your command in the terminal, you can redirect your output to the HTML document. This will allow you to see the output in the web browser like the website. I will assume, you know the basics of HTML. Even if you don’t, it’s very easy to learn. Find some good tutorials and get started.Now, let’s get started by writing a simple shell script with HTML tags in it.

echo "<htmL>"
echo "<head>"
echo "<title>"
echo "Output in a HTML Document"
echo "</title>"
echo "</head>"
echo "<body>"
cat freshtutorial
echo "</body>"
echo "</html>"

This simple shell script called “test” will display the file called freshtutorial which I have already created in my home directory. Every HTML tags have to be quoted with echo. Redirect the
script to HTML document.

sh test >> test.html

Open the test.html and see the output. Instead of creating a output into the terminal itself, it redirects the output to a webpage.

shell script to create html document We don’t want to put echo in every HTML tags. This will make our job tedious and dirty. Thus to simplify this we will use “<< “.

display="HELLO WORLD"
cat << noEcho
<TITLE> Cool Bash trick </TITLE>

“noEcho” is called token in the above script named “display”. You can assign any token as you want besides the bash keywords. Redirect the script into a webpage issuing the following command:

sh display >> display.html

This all might seem confusion at the beginning. Once you get used to it, it feels amazing. It is a nice cool shell programming trick as well. If you have any confusion, feel free to ask questions as comment.

Posted in Shell Scripting | Tagged , , | 2 Comments

2 Responses to Create a HTML Document using shell script in Linux

  1. Abiru JAPAN Mozilla Firefox Ubuntu Linux says:

    sh test <> test.html

  2. Hi friends, its enormous paragraph about educationand completely explained, keep it up all the time.
    Buy Cartridge

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>