NetBSD-Bugs archive

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

bin/55613: NetBSD /bin/sh Remove Largest Suffix Pattern, Remove Largest Prefix Pattern do not work



>Number:         55613
>Category:       bin
>Synopsis:       NetBSD /bin/sh Remove Largest Suffix Pattern, Remove Largest Prefix Pattern do not work
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Aug 29 02:10:00 +0000 2020
>Originator:     Bruce Lilly
>Release:        9.0
>Organization:
>Environment:
NetBSD cq60-615dx.blilly.net 9.0 NetBSD 9.0 (GENERIC) #0: Fri Feb 14 00:06:28 UTC 2020  mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/amd64/compile/GENERIC amd64 x86_64 Intel 686-class NetBSD
>Description:
Parameter expansion with largest matching leading/trailing suffix as described in the man page sections "Remove Largest Suffix Pattern" and "Remove Largest Prefix Pattern" subsections of "Parameter Expansion" do not work.

Example: given a directory part (which might have trailing slashes) and a basename part (which might have leading slashes), a proper path can be constructed by concatenating the directory part with trailing slashes elided, a single slash, and the basename part with any leading slashes elided.
>How-To-Repeat:
dir=foo///
base=///bar
path=${dir%%+(/)}/${base##+(/)}

or equivalent (there are many ways to specify each of the three parts).

Example:
$ sh shellbug
Running sh from /bin/sh
         Copyright (c) 1991, 1993 The Regents of the University of California.  All rights reserved.
dir=foo/// separator1=/ separator2(octal escape)=\057 number0=* number1=+ pattern1=${number1}(${separator1})=+(/) pattern2=${number0}([${separator2}])=*([\057]) base=///bar
path=${dir%%${pattern1}}${separator1}${base##${pattern2}}=foo///////bar
$ ksh93 shellbug
Running ksh93 from /usr/pkg/bin/ksh93
        $Id: Version AJM 93u+ 2012-08-01 $
dir=foo/// separator1=/ separator2(octal escape)=\057 number0=* number1=+ pattern1=${number1}(${separator1})=+(/) pattern2=${number0}([${separator2}])=*([\057]) base=///bar
path=${dir%%${pattern1}}${separator1}${base##${pattern2}}=foo/bar
path=${dir/%${pattern1}/${separator1}}${base/#${pattern2}/}=foo/bar

Note: ksh93 also supports parameter expansion with pattern substitution (last line) which cause /bin/sh to emit a syntax error (even when the sequence is is a non-executable branch of an if or case statement) and exit.
>Fix:
One possible solution is to use ksh93 as /bin/sh (there's even a statically-linked version that might be suitable for /rescue).



Home | Main Index | Thread Index | Old Index