GNU bug report logs -
#18449
"cat x >> x" error even when x is empty
Previous Next
Full log
Message #17 received at 18449 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
With my Fedora version, there is an error message (input file is output file)
cat x >x
cat: x: input file is output file
Regards
Leslie
>________________________________
> From: Pádraig Brady <P <at> draigBrady.com>
>To: Vincent Lefevre <vincent <at> vinc17.net>; 18449 <at> debbugs.gnu.org
>Sent: Thursday, September 11, 2014 9:20 AM
>Subject: bug#18449: "cat x >> x" error even when x is empty
>
>
>On 09/11/2014 02:00 PM, Vincent Lefevre wrote:
>> With coreutils 8.23 under Debian/unstable:
>>
>> ypig% : > x
>> ypig% cat x >> x
>> cat: x: input file is output file
>> ypig% POSIXLY_CORRECT=1 cat x >> x
>> cat: x: input file is output file
>>
>> while there's no reason to return an error in this case: the file
>> should just remain empty. Using the same file for input and output
>> isn't disallowed by POSIX, AFAIK.
>>
>> This may not seem really useful here, but this can potentially break
>> scripts with things like:
>>
>> cat "$foo" >> "$bar"
>>
>> where "$foo" may be the same file as "$bar" only if it is empty.
>
>I'm struggling to see that use case TBH.
>
>
>> BTW, when x isn't empty, I wonder whether an error is correct if
>> POSIXLY_CORRECT is set. The result will typically depend on the
>> implementation and possibly be non-deterministic, but POSIX doesn't
>> seem to allow an error (except FS errors, such as disk full).
>
>This is just a protection against non deterministic usage.
>I.E. if there is data in the file then it'll probably run
>until the file system is exhausted. This is what happens
>on FreeBSD BTW, though I see that Solaris has the same
>protections as GNU.
>
>I wouldn't be on for removing this protection which
>has existed from the initial GNU implementation.
>
>cheers,
>Pádraig.
>
>
>
>
>
>
>
[Message part 2 (text/html, inline)]
This bug report was last modified 10 years and 251 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.