NetBSD Problem Report #61048
From www@netbsd.org Mon Nov 23 00:25:28 2026
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
client-signature RSA-PSS (2048 bits) client-digest SHA256)
(Client CN "mail.netbsd.org", Issuer "YR1" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 9550B1A923B
for <gnats-bugs@gnats.NetBSD.org>; Mon, 23 Nov 2026 00:25:28 +0000 (UTC)
Message-Id: <20261123002517.491DB1A923D@mollari.NetBSD.org>
Date: Mon, 23 Nov 2026 00:25:17 +0000 (UTC)
From: greywolf@starwolf.com
Reply-To: greywolf@starwolf.com
To: gnats-bugs@NetBSD.org
Subject: sort(1) not behaving as expected, requiring two passes
X-Send-Pr-Version: www-1.0
X-From4GNATS: "greywolf@starwolf.com via gnats" <gnats-admin@NetBSD.org>
>Number: 61048
>Category: bin
>Synopsis: sort(1) not behaving as expected, requiring two passes
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Nov 23 00:30:00 +0000 2026
>Last-Modified: Mon Nov 23 15:35:01 +0000 2026
>Originator: Greywolf
>Release: NetBSD-10-1-RELEASE
>Organization:
>Environment:
NetBSD valentina.serenity.starwolf.com 11.0 NetBSD 11.0 (VALENTINA) #11: Thu Sep 3 21:24:44 PDT 2026 greywolf@valentina.serenity.starwolf.com:/usr/src/sys/arch/amd64/compile/VALENTINA amd64
>Description:
[please disregard the oddity of the awk command; this is part of the mechanics of a script.]
When I take the output of
cd /usr/src
cvs status -v | awk '$1 ~ pat {print $1}' pat='.*' |
grep RELEASE |
sort -nrt- -k2,3,4
it seems to sort by field 2, reversed and then by field 3, forward.
I have to run the grep output through sort -t- first, then through the sort -nrt- -k2,3,4 in order to get the list fully sorted.
I observe that if the number of fields is consistent, the sort seems to work right the first time.
>How-To-Repeat:
3 sections here:
- the script
- what I expected
- what I got
No, I do not have a fix because I have no idea what is going wrong.
1. THE SCRIPT [cvs-showtags]
#! /bin/sh -
#
# send-pr note: Yes, I know I do not need to go through creating
# temp files for this -- this was done for debugging.
# Yes, I know sort takes a filename for its input and I do not need
# an input redirect. I will clean this all up later.
#
VER="cvs-showtags 1.1 greywolf 2026-11-22 14:37 PST";
RELFILE=$(mktemp /tmp/.relXXXXX);
trap 'rm -f ${RELFILE} ${RELFILE}-*' 0;
showall=false latest=false releaseonly=false;
while getopts :alr x; do {
case $x in
a)
showall=true;
;;
l)
latest=true;
;;
r)
releaseonly=true;
;;
?)
exit 1;
;;
esac
} done;
shift $((OPTIND - 1));
if ! $(expr "${PWD}" : /usr/src > /dev/null); then {
cd /usr/src;
} fi;
if ${showall}; then {
pat='.*';
}
else {
pat='^netbsd';
} fi;
cvs status -v build.sh > ${RELFILE}
awk '$1 ~ pat { print $1; }' pat="$pat" ${RELFILE} > ${RELFILE}-awk;
{
{ ${releaseonly:=false} && grep RELEASE || cat; } |
{ ${latest:=false} && head -1 || cat; }
} < ${RELFILE}-awk > ${RELFILE}-filtered
sort -t- -rn -k2,3,4 < ${RELFILE}-filtered
exit;
::::
: run via: :
cvs-showtags -r
2. WHAT I EXPECTED
netbsd-11-1-RELEASE
netbsd-11-0-RELEASE
netbsd-10-2-RELEASE
netbsd-10-1-RELEASE
netbsd-10-0-RELEASE
netbsd-9-5-RELEASE
netbsd-9-4-RELEASE
netbsd-9-3-RELEASE
netbsd-9-2-RELEASE
netbsd-9-1-RELEASE
netbsd-9-0-RELEASE
netbsd-8-3-RELEASE
netbsd-8-2-RELEASE
netbsd-8-1-RELEASE
netbsd-8-0-RELEASE
netbsd-7-2-RELEASE
netbsd-7-1-2-RELEASE
netbsd-7-1-1-RELEASE
netbsd-7-1-RELEASE
netbsd-7-0-2-RELEASE
netbsd-7-0-1-RELEASE
netbsd-7-0-RELEASE
netbsd-6-0-6-RELEASE
netbsd-6-1-5-RELEASE
netbsd-6-1-4-RELEASE
netbsd-6-0-5-RELEASE
netbsd-6-1-3-RELEASE
netbsd-6-0-4-RELEASE
netbsd-6-1-2-RELEASE
netbsd-6-0-3-RELEASE
netbsd-6-1-1-RELEASE
netbsd-6-0-2-RELEASE
netbsd-6-1-RELEASE
netbsd-6-0-1-RELEASE
netbsd-6-0-RELEASE
netbsd-5-2-3-RELEASE
netbsd-5-1-5-RELEASE
netbsd-5-2-2-RELEASE
netbsd-5-1-4-RELEASE
netbsd-5-2-1-RELEASE
netbsd-5-1-3-RELEASE
netbsd-5-2-RELEASE
netbsd-5-1-2-RELEASE
netbsd-5-1-1-RELEASE
netbsd-5-1-RELEASE
netbsd-5-0-2-RELEASE
netbsd-5-0-1-RELEASE
netbsd-5-0-RELEASE
netbsd-4-0-1-RELEASE
netbsd-4-0-RELEASE
netbsd-3-1-1-RELEASE
netbsd-3-0-3-RELEASE
netbsd-3-1-RELEASE
netbsd-3-0-2-RELEASE
netbsd-3-0-1-RELEASE
netbsd-3-0-RELEASE
netbsd-2-0-3-RELEASE
netbsd-2-1-RELEASE
netbsd-2-0-2-RELEASE
netbsd-2-0-1-RELEASE
netbsd-2-0-RELEASE
netbsd-1-6-PATCH002-RELEASE
netbsd-1-6-PATCH001-RELEASE
netbsd-1-6-RELEASE
----
3. WHAT I GOT
netbsd-11-0-RELEASE
netbsd-11-1-RELEASE
netbsd-10-0-RELEASE
netbsd-10-1-RELEASE
netbsd-10-2-RELEASE
netbsd-9-0-RELEASE
netbsd-9-1-RELEASE
netbsd-9-2-RELEASE
netbsd-9-3-RELEASE
netbsd-9-4-RELEASE
netbsd-9-5-RELEASE
netbsd-8-0-RELEASE
netbsd-8-1-RELEASE
netbsd-8-2-RELEASE
netbsd-8-3-RELEASE
netbsd-7-0-RELEASE
netbsd-7-0-1-RELEASE
netbsd-7-0-2-RELEASE
netbsd-7-1-RELEASE
netbsd-7-1-1-RELEASE
netbsd-7-1-2-RELEASE
netbsd-7-2-RELEASE
netbsd-6-0-RELEASE
netbsd-6-0-1-RELEASE
netbsd-6-1-RELEASE
netbsd-6-0-2-RELEASE
netbsd-6-1-1-RELEASE
netbsd-6-0-3-RELEASE
netbsd-6-1-2-RELEASE
netbsd-6-0-4-RELEASE
netbsd-6-1-3-RELEASE
netbsd-6-0-5-RELEASE
netbsd-6-1-4-RELEASE
netbsd-6-1-5-RELEASE
netbsd-6-0-6-RELEASE
netbsd-5-0-RELEASE
netbsd-5-0-1-RELEASE
netbsd-5-0-2-RELEASE
netbsd-5-1-RELEASE
netbsd-5-1-1-RELEASE
netbsd-5-1-2-RELEASE
netbsd-5-2-RELEASE
netbsd-5-1-3-RELEASE
netbsd-5-2-1-RELEASE
netbsd-5-1-4-RELEASE
netbsd-5-2-2-RELEASE
netbsd-5-1-5-RELEASE
netbsd-5-2-3-RELEASE
netbsd-4-0-RELEASE
netbsd-4-0-1-RELEASE
netbsd-3-0-RELEASE
netbsd-3-0-1-RELEASE
netbsd-3-0-2-RELEASE
netbsd-3-1-RELEASE
netbsd-3-0-3-RELEASE
netbsd-3-1-1-RELEASE
netbsd-2-0-RELEASE
netbsd-2-0-1-RELEASE
netbsd-2-0-2-RELEASE
netbsd-2-1-RELEASE
netbsd-2-0-3-RELEASE
netbsd-1-6-RELEASE
netbsd-1-6-PATCH001-RELEASE
netbsd-1-6-PATCH002-RELEASE
>Fix:
>Audit-Trail:
From: mlelstv@serpens.de (Michael van Elst)
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: bin/61048: sort(1) not behaving as expected, requiring two passes
Date: Mon, 23 Nov 2026 06:51:38 -0000 (UTC)
gnats-admin@NetBSD.org ("greywolf@starwolf.com via gnats") writes:
>sort -nrt- -k2,3,4
>it seems to sort by field 2, reversed and then by field 3, forward.
The -k option is [-k [kstart[,kend]], so kstart=2 and kend=3, the
trailing ",4" is ignored. The single sort key is therefore the
value spanning fields 2 to 3 including the separator, e.g. "11-1".
The numeric comparison of that field then ignores all the trailing
characters beginning from the separator.
What you probably want is:
sort -nrt- -k2 -k3 -k4
to sort by fields 2, 3 and 4 individually.
From: Valery Ushakov <uwe@stderr.spb.ru>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: bin/61048: sort(1) not behaving as expected, requiring two passes
Date: Mon, 23 Nov 2026 18:30:26 +0300
On Mon, Nov 23, 2026 at 00:30:01 +0000, greywolf@starwolf.com via gnats wrote:
> 1. THE SCRIPT [cvs-showtags]
Please, provide the input to be sorted, not a script that queries
external data sources to create the data to be sorted.
-uwe
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.