*BSD News Article 83266


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!munnari.OZ.AU!news.ecn.uoknor.edu!feed1.news.erols.com!howland.erols.net!news.mathworks.com!news.pbi.net!samba.rahul.net!rahul.net!a2i!rootbear.a2i!rootbear
From: "James W. Williams" <rootbear@rahul.net>
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: cat foo* > foo.bar    causes infinite loop
Date: 19 Nov 1996 20:22:03 GMT
Organization: a2i network
Lines: 20
Message-ID: <56t4tb$b93@samba.rahul.net>
References: <328A1236.32C4@pilot.msu.edu> <56itkk$h59$1@nic.wat.hookup.net> <56mktc$b4a@uriah.heep.sax.de>
NNTP-Posting-Host: foxtrot.rahul.net
NNTP-Posting-User: rootbear

I mentioned this thread to a friend and he gave me another historic
perspective on it.  In sixth edition unix, and probably earlier versions,
the expansion of filename patterns was done by the glob program.  If I
got it right, what the shell did with

% prog -x -y -z *.foo < bar > baz

was to fork a subshell, which would set up the redirection of stdin to bar
and stdout to baz, thus creating baz if it didn't exist. Then the subshell
would overlay itself (exec) with:

glob prog -x -y -z *.foo

and the glob program would look for things in the argument list to expand.
Finally, glob would exec prog with the expanded argument list.

So, the redirected stdout output file was created well before filename
expansion and it was done by a different program!

Jim