*BSD News Article 82896


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!munnari.OZ.AU!spool.mu.edu!uwm.edu!www.nntp.primenet.com!nntp.primenet.com!cpk-news-hub1.bbnplanet.com!news.bbnplanet.com!su-news-hub1.bbnplanet.com!news.sgi.com!olivea!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: 14 Nov 1996 22:10:49 GMT
Organization: a2i network
Lines: 25
Message-ID: <56g5d9$frp@samba.rahul.net>
References: <328A1236.32C4@pilot.msu.edu> <56d9io$ijc@newshost.lanl.gov>
NNTP-Posting-Host: foxtrot.rahul.net
NNTP-Posting-User: rootbear

In article <328A1236.32C4@pilot.msu.edu>,
Ed Symanzik  <zik@pilot.msu.edu> wrote:
= If I create three files foo1, foo2, and foo3 then run the command
= 
=  cat foo* > foo.bar
= 
= in csh I get an infinite loop (at least until the partition fills up).
= Seems to me that '*' should be evaluated before new files are created.
= I have seen systems that don't behave this way give errors similar to
= "can't open foo.bar for both input and output".

I ran into this "bug" on a VAX running BSD 3.x in the early 80s.  At
the time, the rationale I was given for why csh created the output file
before doing the filename expansion was one of efficiency.  You don't
want to do the expensive filename globing operatation if the command will
then fail when creating the output file for redirection, so do the less
expensive redirection first.  If it succeeds, then do the more expensive
globbing.

Now that machines are so much faster, this is perhaps not a compelling
argument in favor of this ordering.  Doing the globbing first seems to me
to be more in line with the principle of least astonishment.

Jim