cat problem ???

James Gray james.gray at dot.com.au
Thu Dec 21 23:00:46 UTC 2006


On Friday 22 December 2006 09:21, John Dangler wrote:
> On Fri, 2006-12-22 at 00:15 +0200, Dimitri Mallis wrote:
> > hi all
> >
> > i want to create scripts from the command line using cat... but...
> >
> > dimitri at programming:~/SCRIPTS$ cat penguin.sh
> > cat: penguin.sh: No such file or directory
> >
> > in all the example tutorials i have looked at cat is supposed to
> > create the file for you if it does not exist :(
> > i have to use gedit each time, which is nice because it has syntax
> > highlighting :)
> >
> > I'd just like to know why cat doesn't create a file if it doesn't
> > exist
> >
> > ( i have looked at man cat & info cat, but i couldn't find my solution
> > there)
> >
> > any thoughts?
> > thankshttp://www.digg.com/tech_news/World_s_Best_Geek_Christmas_Party
>
> cat > filename  will create a new file
> cat >> filename will append to an existing file

This is being pedantic, but the examples above, whilst 100% correct, have 
little to do with "cat" doing anything to the filesystem.  The file 
operations are actually being handled by shell redirection :)

Consider (for the OP):

$ cat - << EOF >> foo.txt
Hello from
the console
EOF
$ cat foo.txt
Heloo from
the console
$

Have a think about it, then retry it with
$ cat - << EOF > foo.txt

Cheers,

James
-- 
It takes a smart husband to have the last word and not use it.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20061222/321739fd/attachment.pgp>


More information about the ubuntu-users mailing list