GNU bug report logs -
#17384
"bug" in the Unix "cat" command
Previous Next
Reported by: Peter Rowat <peter <at> pelican.ucsd.edu>
Date: Thu, 1 May 2014 19:12:02 UTC
Severity: normal
Tags: notabug
Done: Paul Eggert <eggert <at> cs.ucla.edu>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 17384 in the body.
You can then email your comments to 17384 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-coreutils <at> gnu.org
:
bug#17384
; Package
coreutils
.
(Thu, 01 May 2014 19:12:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Peter Rowat <peter <at> pelican.ucsd.edu>
:
New bug report received and forwarded. Copy sent to
bug-coreutils <at> gnu.org
.
(Thu, 01 May 2014 19:12:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hello Gnu folks,
I had 3 files matching “isi.*.02p0:
wc -l isi.*.02p0
20000 isi.R.0400.02p0
15500 isi.Ra.0400.02p0
15600 isi.Rb.0400.02p0
51100 total
I wanted to combine them into one big file, while knowing *not* to cat into a file with same name as an original file,
I did this:
cat isi.*.02p0 >isi.Rall.0400.02p0
But it never returned!!
By the time I hit Ctrl-C, the file isi.Rall.0400.02p0 was already 3000 times bigger than the biggest of the original files.
A hidden loop was made.
Because the destination file was created before concatenation started, it became a match for the
pattern "isi.*.02p0”.
It might be worth adding a warning about this on the cat man-page ??
Cheers,
— Peter Rowat
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#17384
; Package
coreutils
.
(Thu, 01 May 2014 20:54:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 17384 <at> debbugs.gnu.org (full text, mbox):
tags 17384 + moreinfo
thanks
On 05/01/2014 08:50 PM, Peter Rowat wrote:
> Hello Gnu folks,
>
> I had 3 files matching “isi.*.02p0:
>
> wc -l isi.*.02p0
> 20000 isi.R.0400.02p0
> 15500 isi.Ra.0400.02p0
> 15600 isi.Rb.0400.02p0
> 51100 total
>
> I wanted to combine them into one big file, while knowing *not* to cat into a file with same name as an original file,
> I did this:
>
> cat isi.*.02p0 >isi.Rall.0400.02p0
>
>
> But it never returned!!
> By the time I hit Ctrl-C, the file isi.Rall.0400.02p0 was already 3000 times bigger than the biggest of the original files.
>
> A hidden loop was made.
>
> Because the destination file was created before concatenation started, it became a match for the
> pattern "isi.*.02p0”.
>
> It might be worth adding a warning about this on the cat man-page ??
Thanks for the bug report.
However I cannot reproduce the problem.
On my system (openSUSE-13.1), the output file is created with exactly
the 51100 lines as expected:
$ seq 20000 > isi.R.0400.02p0
$ seq 15500 > isi.Ra.0400.02p0
$ seq 15600 > isi.Rb.0400.02p0
$ wc -l isi.*.02p0
20000 isi.R.0400.02p0
15500 isi.Ra.0400.02p0
15600 isi.Rb.0400.02p0
51100 total
$ src/cat isi.*.02p0 >isi.Rall.0400.02p0
$ wc -l isi.*.02p0
20000 isi.R.0400.02p0
15500 isi.Ra.0400.02p0
51100 isi.Rall.0400.02p0
15600 isi.Rb.0400.02p0
102200 total
If the output file had previously existed (so that the file name
globbing would let it match the pattern), then cat(1) would have
complained:
$ src/cat isi.*.02p0 >isi.Rall.0400.02p0
src/cat: isi.Rall.0400.02p0: input file is output file
That means that on your system
a) the shell opened the output file before doing the pattern matching,
and b) cat(1) was unable to detect that the output file is the same
as the input file.
As that check is included in GNU coreutils' cat(1) since day one,
this issue is not a matter of an outdated version of cat(1).
What system are you using (OS, file system type, shell, shell version,
and finally 'cat --version')?
Can you confirm that the previously non-existing output file was
matched by the pattern using "set -x" before issuing the command?
When the output file did not previously exist:
$ ( set -x; src/cat isi.*.02p0 >isi.Rall.0400.02p0 )
+ src/cat isi.R.0400.02p0 isi.Ra.0400.02p0 isi.Rb.0400.02p0
When the output file already exists:
$ ( set -x; src/cat isi.*.02p0 >isi.Rall.0400.02p0 )
+ src/cat isi.R.0400.02p0 isi.Ra.0400.02p0 isi.Rall.0400.02p0 isi.Rb.0400.02p0
src/cat: isi.Rall.0400.02p0: input file is output file
Thanks & have a nice day,
Berny
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#17384
; Package
coreutils
.
(Fri, 02 May 2014 13:17:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 17384 <at> debbugs.gnu.org (full text, mbox):
tags 17384 notabug
close 17384
stop
On 05/01/2014 10:52 PM, Bernhard Voelker wrote:
> If the output file had previously existed (so that the file name
> globbing would let it match the pattern), then cat(1) would have
> complained:
>
> $ src/cat isi.*.02p0 >isi.Rall.0400.02p0
> src/cat: isi.Rall.0400.02p0: input file is output file
>
> That means that on your system
> a) the shell opened the output file before doing the pattern matching,
> and b) cat(1) was unable to detect that the output file is the same
> as the input file.
> As that check is included in GNU coreutils' cat(1) since day one,
> this issue is not a matter of an outdated version of cat(1).
>
> What system are you using (OS, file system type, shell, shell version,
> and finally 'cat --version')?
As confirmed in private email, the system was "Mac OS X 10.9.2 (Mavericks)"
... and the OP was using the Apple version of 'cat'.
I'm therefore marking this as not a bug and closing it.
Have a nice day,
Berny
Added tag(s) notabug.
Request was from
Paul Eggert <eggert <at> cs.ucla.edu>
to
control <at> debbugs.gnu.org
.
(Mon, 02 Jun 2014 17:52:01 GMT)
Full text and
rfc822 format available.
bug closed, send any further explanations to
17384 <at> debbugs.gnu.org and Peter Rowat <peter <at> pelican.ucsd.edu>
Request was from
Paul Eggert <eggert <at> cs.ucla.edu>
to
control <at> debbugs.gnu.org
.
(Mon, 02 Jun 2014 17:52:02 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Tue, 01 Jul 2014 11:24:05 GMT)
Full text and
rfc822 format available.
This bug report was last modified 10 years and 355 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.