[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Possible bug in sort 5.97

From: Pádraig Brady
Subject: Re: Possible bug in sort 5.97
Date: Fri, 28 Sep 2007 14:02:20 +0100
User-agent: Thunderbird (X11/20070919)

address@hidden 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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]