From: hamilton@BIX.com (hamilton on BIX)
Newsgroups: comp.unix.shell
Subject: Re: Filename expansion in C shell
Date: 9 Sep 95 15:06:10 GMT
Organization: Delphi Internet Services Corporation

gi101@cus.cam.ac.uk (G. Ioannou) writes:


>I have two files named simcity.000 and simcity.001 in a certain
>directory.  These were derived by splitting a file called
>simcity.gz.  I want to recombine them so I do:

>    % cat simc* > simcity.gz

>When I did this with a number of Bourne shell variants it worked
>as I would expect it to: created a new file simcity.gz and wrote
>to it the contents first of simcity.000 then simcity.001.

>When I tried it with the C shell (under FreeBSD 2.0.5 if it makes
>any difference) it seemed to take an awfully long time to
>complete, and made a lot of hard disk noise... I suspended the
>process and did an ls -l.  The original files were still there
>and intact, and also simcity.gz, however the size of this file
>was very big.  In other words, I had created an infinite loop of
>some kind.

>Could some kind soul explain to me how this could happen?  Thanks
>in advance for any help.

The C shell processes redirections before doing the wildcarding.  This
is one of those design decisions in a shell that could go either way,
as you've discovered.  Some designers will certainly believe that it
should be done one way, others will choose the opposite.  There is no
right or wrong here, merely a matter of making a choice and living
with the consequences.

If wildcarding is after redirecting, then obviously you do avoid the
problem you encountered here.  On the other hand, it becomes more
difficult to implement language structures like this:

   ( ...create new files...; ...wildcard those new files... ) > output

because the new files won't yet exist at the time the wildcarding is
being done since obviously there is absolutely no choice about whether
to do the redirection before executing the statement that will create
them.

Regards,
Doug Hamilton  KD1UJ  hamilton@bix.com  Ph 508-440-8307  FAX 508-440-8308
Hamilton Laboratories, 21 Shadow Oak Drive, Sudbury, MA  01776-3165, USA

