NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: bin/59896: tr extends string2 incorrectly when [#*0] is specified
The following reply was made to PR bin/59896; it has been noted by GNATS.
From: RVP <rvp%SDF.ORG@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc:
Subject: Re: bin/59896: tr extends string2 incorrectly when [#*0] is
specified
Date: Sat, 10 Jan 2026 07:32:51 +0000 (UTC)
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
--0-2034718689-1768030371=:12460
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8BIT
On Wed, 7 Jan 2026, jarle.greipsland%norid.no@localhost via gnats wrote:
> NetBSD tr:
> $ echo A N Y | tr A-Z 'a-c[q*20]x-z'
> a q y
> which is the expected output.
>
> $ echo A N Y | tr A-Z 'a-c[q*0]x-z'
> a q q
> should have been equivalent to the first expression, but it isn't.
>
> The man page states:
> ... If n is omitted or is zero, it is interpreted as
> large enough to extend the string2 sequence to the length of
> string1. If n has a leading zero, it is interpreted as an
> octal value; otherwise, it is interpreted as a decimal
> value.
>
It seems to me that this says `[q*]' will extend `string2' to the remaining
length of `string1' first, then `x-z' will get tacked on, exceeding len. of
`string1', and therefore will not be used.
> It seems like NetBSD's tr does not take into account any characters
> in string2 found after the [#*n] expression.
>
But, should it?
> GNU tr from coreutils behaves as I would expect:
> $ echo A N Y | gtr A-Z 'a-c[q*20]x-z'
> a q y
> $ echo A N Y | gtr A-Z 'a-c[q*0]x-z'
> a q y
>
GNU tr(1) seems to be the only one which does this. Both OpenBSD and FreeBSD
tr behave like NetBSD's; as does the tr in OpenIndiana 2025.10.
-RVP
PS. I like what GNU tr(1) does, but, I'd like clarification on this first,
vis-à-vis POSIX and historical behaviour. :)
--0-2034718689-1768030371=:12460--
Home |
Main Index |
Thread Index |
Old Index