Kenn Humborg wrote:
> > > On Fri, 11 Feb 2000 20:02:33 -0000 "Kenn Humborg" <kenn at bluetree.ie>
> > > wrote:
> > > | > sed 's/ *| */|/g' file | cat > file
> > >
> > > | > surely ??
> > >
> > > | Is that _guaranteed_ not to truncate 'file' before sed
> > > | reads it?
> > >
> > well, yes it should do, because its handing the output to cat before being
> > piped back into itself . . . now of course thats down to how much info cat
> > can hold . . . but you certainly shouldn't see sed overwrite the file it's
> > trying to parse
>> I'd have to disagree. I'd see it working like this:
>> 1. Shell breaks up pipeline into two commands:
>> sed -e '...' file
>> cat > file
>> 2. It creates a pipe.
>> 3a. To execute the first command, it creates an argv array,
> hooks fd 1 up to the pipe's input and forks/execs.
>> 3b. To execute the second command, it opens 'file' for writing
> on fd 1, which should truncate the file. Then it forks
> and execs cat.
>> So, depending on the order in which 3a and 3b are done, sed
> might get enough time to read all of file (if it is short and
> in-cache) before the shell truncates it.
>
This is an inherently incorrect thing to do, it may work occasionally for small
files, depending on system load etc...., but will generally screw up.
--
===============================================================================
John Allen, Email: john.allen at oc2.com
Orbis Payment Technology Ltd, Phone: +353-1-2945111
3 Sandyford Park, Mobile: +353-86-2315986
Sandyford Industrial Estate, Fax: +353-1-2945119
Dublin 18.
===============================================================================
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!