From owner-freebsd-hackers Wed Jul 19 19:39:59 1995 Return-Path: hackers-owner Received: (from majordom@localhost) by freefall.cdrom.com (8.6.11/8.6.6) id TAA12864 for hackers-outgoing; Wed, 19 Jul 1995 19:39:59 -0700 Received: from staff.cs.su.OZ.AU (staff.cs.su.OZ.AU [129.78.8.1]) by freefall.cdrom.com (8.6.11/8.6.6) with SMTP id TAA12820 for ; Wed, 19 Jul 1995 19:39:55 -0700 Received: from osix.osix.oz.au by staff.cs.su.OZ.AU (mail from daemon for hackers@freebsd.org) with MHSnet; Thu, 20 Jul 1995 12:39:45 +1000 Received: from blain.osix.oz.au by osix.osix.oz.au (AIX 3.2/UCB 5.64/4.03.OSIX.001) id AA13474; Wed, 19 Jul 1995 20:22:43 -0500 Received: (from peter@localhost) by blain.osix.oz.au (8.6.11/8.6.9) id LAA07988; Thu, 20 Jul 1995 11:22:42 +1000 From: Peter May Message-Id: <199507200122.LAA07988@blain.osix.oz.au> Subject: Re: Being curious with `cat * > file' To: mbarkah@hemi.com (Ade Barkah) Date: Thu, 20 Jul 95 11:22:42 WET Cc: hackers@freebsd.org In-Reply-To: <199507192022.OAA10037@hemi.com>; from "Ade Barkah" at Jul 19, 95 02:22:50 pm X-Mailer: ELM [version 2.4dev PL17] Sender: hackers-owner@freebsd.org Precedence: bulk Ade Barkah spoke thus: > Hello, > What should `cat * > output` do ? Should it gracefully concatenate > all the files together into a file called `output', or will it > attempt to cat the output into itself so many times until the > file system is filled ? Sort of. It will expand the '*' in alphabetical order, which is why you are getting this below. > Here's a sample session: > barkah: {1} mkdir test1 > barkah: {2} cd test1 > barkah: {3} cat >> testfile < test file > barkah: {4} cat * > output > barkah: {5} ls -l > total 4 > -rw-rw-r-- 1 mbarkah userm 10 Jul 19 13:50 output > -rw-rw-r-- 1 mbarkah userm 10 Jul 19 13:50 testfile The shell created the file output with length 0 before it exec'd the cat command. It then would have run the command: cat output testfile with output redirected to output. Since output was a zero length file at this point, it "copied" zero bytes from output to output. Then it copied the contents of testfile to output and you ended up with a 10 byte file "output" > [Looks great up to this point, works as expected] > barkah: {6} cat * > output2 > [Job killed with ctrl-c at this point] > barkah: {7} ls -l > total 916 > -rw-rw-r-- 1 mbarkah userm 10 Jul 19 13:50 output > -rw-rw-r-- 1 mbarkah userm 454360 Jul 19 13:50 output2 > ^^^^^^ > -rw-rw-r-- 1 mbarkah userm 10 Jul 19 13:50 testfile This is also expected, consider how the shell would have handled the filename expansion: (Creates empty file output2) cat output output2 testfile With standard output redirected to output2. First, it cat's the contents of output (which is 10 bytes) into output2, then it copies the contents of output2 to output2, which is at first 10 bytes, but keeps growing add infinitum. It never gets to testfile. If you want to prove it (it's based on alphabetic order) try: (with just output and testfile in the directory) cat '*' > aoutput As aoutput is the first file processed, it would work as expected. The issue is when the shell does filename expansion. In some shells, the expansion is done before redirection is processed. This does not appear to be the case in the shell you are using. > -Ade Barkah > -------------------------------------------------------------------- > Inet: mbarkah@hemi.com - HEMISPHERE ONLINE - www: > -------------------------------------------------------------------- Regards, ---------------------------------------------------------------->>>>> Peter May OSIX Pty Ltd Director Level 1, 261-263 Pacific Highway Technical Services North Sydney. NSW. Australia. 2060. Home: +61-2-418-7656 Internet: peter@osix.oz.au Work: +61-2-922-3999 Fax: +61-2-922-3314 >>>> PGP Public key available upon request <<<< ---------------------------------------------------------------->>>>>