tag 21880 notabug thanks On 11/11/2015 11:50 AM, Alexander Kindyakov wrote: > Hello! > > In sort man page nothing told about working sort --check with '--key' > option. IMHO this behaviour is strange: Thanks for the report. > > This case is succeeded: > > $ echo -e '1\t2\n1\t1' | LC_ALL=C sort --key=1b,1 --check --stable > --field-separator=$'\t' 'echo -e' is not portable; better is using printf. Let's see what sort was looking at here (it's a shame that --check and --debug can't be used at the same time; but seeing _what_ gets sorted without --check explains whether --check will succeed): $ printf '1\t2\n1\t1\n' | LC_ALL=C sort --debug -k1b,1 -s -t$'\t' sort: using simple byte comparison 1>2 _ 1>1 _ $ So, in this version, you were checking JUST the first field, and nothing else; among the portion of the line checked, everything was identical, so --check has nothing to complain about. > > But this (without option '--stable') is failed: > > $ echo -e '1\t2\n1\t1' | LC_ALL=C sort --key=1b,1 --check > --field-separator=$'\t' > sort: -:2: disorder: 1 1 Again, look at the debug output: $ printf '1\t2\n1\t1\n' | LC_ALL=C sort --debug -k1b,1 -t$'\t' sort: using simple byte comparison 1>1 _ ___ 1>2 _ ___ $ Notice that the removal of --stable behaves as if you had added another --key=1 (that is, sort the ENTIRE line as a last-resort key); and now that you have the entire line involved, --check can indeed see an out-of-order difference in the input. > > It seems to me both of situation is equal with relation of line key, why > does the output is different? The output differs because of your use of --stable. Therefore, this is not a bug in sort, and I'm closing this bug. However, do feel free to add further comments to this thread. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org