On Tuesday 27 Sep 2011, Sagar Belure wrote:
> Can anyone describe what exactly is happening here:
> user@linux:~$ cat << __eof > test.txt
> 
> > anything
> > Anything
> > AnyThing
> > ANYTHING
> > __eof
> 
> user@linux:~$ cat test.txt
> anything
> Anything
> AnyThing
> ANYTHING
> user@linux:~$ cat << anything > test2.txt
> 
> > apple
> > bat
> > cat
> > dog
> > anything
> 
> user@linux:~$ cat test2.txt
> apple
> bat
> cat
> dog
> user@linux:~$
> 
> I really have poor understanding of things happening, but I used this
> method couple of times to write in a file without using any editor.
> So, I would be really happy if someone can explain that in detail,
> or point me to some appropriate place for this.

The general format is:

  command <<SOMESTRING
  line-1
  line-2
  ...
  line-n
  SOMESTRING

Everything between the command line and the next occurance of SOMESTRING 
on a line by itself is treated as standard input to command, just as if 
you'd run the command, typed in lines 1 through n manually and pressed 
^d .

The main drawback, of course, is that you cannot give a line containing 
just SOMESTRING as part of the input -- the moment the shell sees that, 
it treats it as end of input.  In your second example, SOMESTRING == 
anything, so the here document is terminated when you type that in.

For more detailed information, look up "shell here documents" on the 
'net.

Regards,

-- Raj
-- 
Raj Mathur                r...@kandalaya.org      http://kandalaya.org/
       GPG: 78D4 FC67 367F 40E2 0DD5  0FEF C968 D0EF CC68 D17F
PsyTrance & Chill: http://schizoid.in/   ||   It is the mind that moves

-- 
You received this message because you are subscribed to the Google Groups "ILUG 
Bengaluru" group.
To post to this group, send email to ilug-bengaluru@googlegroups.com.
To unsubscribe from this group, send email to 
ilug-bengaluru+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/ilug-bengaluru?hl=en.

Reply via email to