[EMAIL PROTECTED] wrote:
> Hello there.
> I think I have noticed a bug in 'sort' program, version 5.97.
> When I try to sort a non-empty file and I redirect the input
> to the same file as follows
> 
> $ sort testfile > testfile
> 
> the file suddenly gets empty. I think the program should sort
> the file and
> redirects the file sorted to itself. Although the operation
> has no sense, I think this could cause a disaster if I
> mismatch when typing the ouput file.
> Other programs like 'cat' warns me if the input file is the
> same as output, and cancels the operation.

cat warns you, but the file is still truncated.
What's happening is the shell is truncating the file,
before the command (sort in your case) reads it.

Generally you will want to use a temp file like:

sort testfile > testfile.sort
mv testfile.sort testfile

Pádraig.


_______________________________________________
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils

Reply via email to