[tpm] more problems than solutions this week
Liam R E Quin
liam at holoweb.net
Fri May 4 13:28:26 PDT 2012
On Fri, 2012-05-04 at 15:00 -0400, Fulko Hew wrote:
> On Fri, May 4, 2012 at 2:44 PM, <arocker at vex.net> wrote:
> And here I always thought it was because it opens the output
> file first clobbering the original data before it gets a chance
> to open the original data.
Well, you're both right :-)
When you have, sort file > file
first, the shell processes the command, opens "file" for writing, and
truncates it, and associates it with standard output for the subcommand.
Then, the shell forks and exec's /bin/sort with standard output pointing
to the now-empty file.
When sort reads the file, there's nothing there.
In V6 Unix, file pointers were global, and for example there was a goto
command for the shell that changed the file pointer for the current
shell script to point to just after the label, so the next line the
shell read was the next line to execute.
In V7 Unix (1978 or so) file pointers were per process and this was no
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
More information about the toronto-pm