Using Here Documents in Linux

Using Here Documents in Linux


This post was last updated on June 3rd, 2020 at 04:38 pm

cat <<EOF>/tmp/newfile

This is the contents of the here document
It can span multiple lines
A here document says to take all of this text up to the terminating
characters (which in this case are the characters E, O, and F.
I can chose any character string I want to. As soon as the script sees
these characters at the beginning of a line, all by itself with no
trailing whitespace, it will then terminate creating the here document.
Note that I am taking all this text and saving it in the document
called /tmp/newfile. That’s all I have for now, the next line
will contain the magical 3 characters:

Now you can use the new file however you need:
cat /tmp/newfile

Here is a copy of the man page on here documents. You can bring this up
on your system by looking up “Here Documents” in the “bash” man page
(man bash, then type /Here Documents):

Here Documents This type of redirection instructs the shell to read input from the current source until a line containing only word (with no trailing blanks) is seen. All of the lines read up to that point are then used as the standard input for a command. The format of here-documents is: <<[-]word here-document delimiter No parameter expansion, command substitution, arithmetic expansion, or pathname expansion is performed on word. If any characters in word are quoted, the delimiter is the result of quote removal on word, and the lines in the here-document are not expanded. If word is unquoted, all lines of the here-document are subjected to parameter expansion, com- mand substitution, and arithmetic expansion. In the latter case, the character sequence \ is ignored, and \ must be used to quote the characters \, $, and '. If the redirection operator is <<-, then all leading tab characters are stripped from input lines and the line containing delimiter. This allows here-documents within shell scripts to be indented in a natural fashion.
Previous Installing Linux on a Compaq PL2500
Next Proliant 1500 and RedHat 6.2

About author

Sibananda Sahu
Sibananda Sahu 187 posts

A Linux Kernel Developer and a Firmware Developer by profession. Have worked with few big companies: BROADCOM Corporation, Cypress Semiconductor, LSI Corporation, TOSHIBA Corporation, Western Digital; on various cutting edge technologies and product lines, such as: RAID storage Driver, SSD Firmware, WLAN Firmware etc. Having more than 9 years of experience in Software Engineering domain. Now, took a pledge to educate all aspirant students to teach about Linux Kernel Development.

View all posts by this author →

You might also like

System Understanding 0 Comments

Drivers in Linux

This post was last updated on May 26th, 2020 at 10:43 pm Contents0.1 What to do with static drivers, module drivers, append=, and insmod.0.2 Drivers in Linux can take on

System Understanding 0 Comments

Static Routes in RH73 Linux

This post was last updated on June 3rd, 2020 at 04:36 pm(Other routing page: routes.html) Here’s how to set up Red Hat 7.3 /etc/sysconfig/static-routes file, I mention this here because

System Understanding 0 Comments

Linux Loop Devices

This post was last updated on June 1st, 2020 at 07:00 pmBy default you have 8 loop devices (loop0 – loop7). You can extend this number up to 255 (maybe


No Comments Yet!

You can be first to comment this post!

Leave a Reply