PDA

View Full Version : [all variants] Cat syntax and >> and <<



BetterSense
April 17th, 2009, 09:22 PM
I remember seeing an example of how to simply use either echo or cat to send text to a file, with the ability to constantly append until you enter a keyword. It was something like


cat >>mynotes.txt <<EOF

and you could type as long as you wanted until you typed EOF (which could be any 'code word' you wanted. But when I try this now, it acts like it's working, but after I type EOF I get a blank file called mynotes.txt.

StOoZ
April 17th, 2009, 09:53 PM
try for example :

ls -l > mynotes.txt

thats should work...
>> is to append.

kpatz
April 17th, 2009, 09:57 PM
But when I try this now, it acts like it's working, but after I type EOF I get a blank file called mynotes.txt.

That command worked fine for me.



kpatz@jaunty-beta:~$ cat >>mynotes.txt <<EOF
> hello
> there
> how
> are
> you
> EOF
kpatz@jaunty-beta:~$ cat mynotes.txt
hello
there
how
are
you
kpatz@jaunty-beta:~$

llamabr
April 17th, 2009, 11:19 PM
You must exit out of it with ctrl-d, not c or z.