Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-25-2010, 03:58 AM   #1
LQ Newbie
Registered: Aug 2010
Posts: 2

Rep: Reputation: 0
Smile What does the double less than sign (<<) means in creating a new file with cat?

Hi Guys,

Today I saw an article use the following cat command to create a new text file:

$ cat > << END

And then after press the 'return' buttion, a '>' sign appeared expecting you to input the content. If I type 'END' then the 'return' button, then a new text file is created with what I just typed...

I'd like to know what's the differnece in just type:

$ cat >

without the '<<' sign?

What '<<' really means? I cannot find it's meaning anywere... seems it's not in the redirection section...

Old 08-25-2010, 04:12 AM   #2
LQ Guru
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296

The input redirector << means use the current input stream as STDIN for the program until token is seen where token can be anything. Basically you'll get a prompt > where you can type in your commands or whatever until token (END, WHATEVER) is encountered on a new line.

Kind regards,


Last edited by EricTRA; 08-25-2010 at 04:13 AM. Reason: Added more info
1 members found this post helpful.
Old 08-25-2010, 06:49 AM   #3
Senior Member
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 250Reputation: 250Reputation: 250
It appears under the here document description :
A limit string delineates (frames) the command list. The special symbol << designates the limit string....

#  'echo' is fine for printing single line messages,
#+  but somewhat problematic for for message blocks.
#   A 'cat' here document overcomes this limitation.

cat <<End-of-message
This is line 1 of the message.
This is line 2 of the message.
This is line 3 of the message.
This is line 4 of the message.
This is the last line of the message.
Old 08-25-2010, 12:06 PM   #4
Registered: Sep 2006
Location: USA - NYC
Distribution: Whatever icon you see!
Posts: 642

Rep: Reputation: 57
If you want to keep the contents of what you wrote, type

cat << eof > file1
this is line 1
this is line 2
this is line 3
When you type eof, the cat command will terminate and a file called file1 will be created.

Note: eof will not be in the file in case you are wondering.

Last edited by dv502; 08-25-2010 at 12:09 PM.
Old 08-25-2010, 10:21 PM   #5
LQ Newbie
Registered: Aug 2010
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks guys for the replies.
But strange things happens:
if using
$cat > << EOF

any variable is expanded (e.g., if I type $USER in, and later I cat, the var is expanded to its value).
But if I do not use '<<', just cat to a file and save it by ^D, variables are not expanded...
Old 08-25-2010, 11:52 PM   #6
Registered: Jul 2003
Location: Brighton, Michigan, USA
Distribution: Lots of distros in the past, now Linux Mint
Posts: 748

Rep: Reputation: 31
You need an extra level of single quotes if you want to prevent shell variable expansion in Bash, to pacify the '$'. I.e.:

~/testing $ cat > << EOF



~/testing $ cat
\[\033[01;32m\]\w $ \[\033[00m\]

'\[\033[01;32m\]\w $ \[\033[00m\]'


Hope this helps!
Old 08-26-2010, 04:41 AM   #7
Registered: Jun 2004
Location: Zagreb, Croatia
Distribution: Debian Lenny
Posts: 49

Rep: Reputation: 15
For a detailed explanation you can just read the BASH man page. Go here: Man BASH and look for 'Here Documents'.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
cat FILE|sort +1 -n Returns ... +1: No such file or directory musician Linux - Newbie 1 07-23-2009 02:28 PM
cat file over ssh and put it into log file sinister1 Programming 2 04-24-2009 01:54 AM
filesize limit on 'cat $file | sed > $file' drkstr Linux - Software 2 07-10-2006 03:47 AM
trying to redirect text to a file to cat at later point. says file doesn't exist. dr_zayus69 Programming 1 10-02-2005 09:10 AM
What is a SIGN File? giddyupman Linux - Software 1 09-28-2004 10:16 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:01 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration