Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cat and _EOF_ commands 1

Status
Not open for further replies.

ghana123

MIS
Jan 4, 2006
11
SE
I copied the following from a website.
-------------------------

#!/bin/bash

# make_page - A script to produce an HTML file

echo "<HTML>"
echo "<HEAD>"
echo " <TITLE>"
echo " The title of your page"
echo " </TITLE>"
echo "</HEAD>"
echo ""
echo "<BODY>"
echo " Your page content goes here."
echo "</BODY>"
echo "</HTML>"
----------------------------------------------------

The above has rewritten in the following manner.

#!/bin/bash

# make_page - A script to produce an HTML file

cat << _EOF_
<HTML>
<HEAD>
<TITLE>
The title of your page
</TITLE>
</HEAD>
-----------------------------------------------

My question is on the words 'cat ' and ' _EOF_ .

What are they? I believe this strange ' _EOF_ ' means end of the file.

I know the 'cat' command in Linux. If you wrote a text file, you could read it using the 'cat' command.

I can't take in the ' cat ' and _EOF_ in this program.

Could you please tell me about them?
<BODY>
Your page content goes here.
</BODY>
</HTML>
_EOF_
 
Thanks olded for the reply.

It is not easy to understand. I don't know all the aspects of scripting.

However, I am very familiar with the ' cat ' command. When I have a text file, I will always use the ' cat ' command to read it.
[ I guess the word ' cat ' comes from the the English word concatenatenation

To edit a text file, I always use the ' vi ' editor.


-----------------------------------------------------

Another typical use of a here document is replacing a block of echos:

echo "this is line 1"
echo "this is line 2"
echo "this is line 3"

# here document:

cat << HERE
this is line 1
this is line 2
this is line 3
HERE

You can ever embed shell variables in here documents:

x=whatever
cat << HERE
Enter a shell variable
$(echo $x)
HERE


What is the the word ' HERE ' in this scenario?

 
The word HERE is simply a marker showing the start and end of the 'interactive' part and could be (and often is) replaced with almost anything, particularly a ! (bang) for some reason.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top