Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #16841
| Path | csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail |
|---|---|
| From | Bruce Lilly <bruce.lilly@gmail.com> |
| Newsgroups | gnu.bash.bug |
| Subject | Bash parameter expansion (remove largest trailing match, remove largest leading match, pattern replacement) does not work |
| Date | Sat, 29 Aug 2020 10:22:39 -0400 |
| Lines | 60 |
| Approved | bug-bash@gnu.org |
| Message-ID | <mailman.1679.1598712429.2469.bug-bash@gnu.org> (permalink) |
| References | <CAPyES363zNvUZHWo6imXOyC3UPU5FAbsyFGzWkcJMO-HBhT6gQ@mail.gmail.com> |
| NNTP-Posting-Host | lists.gnu.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| X-Trace | usenet.stanford.edu 1598712430 24272 209.51.188.17 (29 Aug 2020 14:47:10 GMT) |
| X-Complaints-To | action@cs.stanford.edu |
| To | bug-bash@gnu.org |
| Envelope-to | bug-bash@gnu.org |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=k39vaRM5HOyNXr0HGlDTH2J6F9T1RiNf40Lbxowc3/Y=; b=rCn+NMAas4FXv4v3KR0UBjebk3wkPtLusFugxI2XCf0TwreAAl4fsQvqjdTZRAF9Td b6xCXmlkbyp3I9TNhaQTs+YBTBczfxf4oSdUVyzBA6rbxchoJbUddJgBq9ehod39/w7i /YdXJPUhqcF7Q7W8JZxUP/WIBCWk95Bv4ZCYuxE6nwFeef3etYmsZjKLZhQ85OceOhIz +T2FlTFlRivPWAQxFQmh89eb1KqUhLk2yUWkdIilyja8BqZQzAfi8FlRQ1V1TdZJ6sTZ B7RpJU/j49LeMZ+WKXmiZQV68eh5n+LP78Ry23cQ4Ga9JlWq5qsBiv/gG+UmnpOpg5sJ DlYQ== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=k39vaRM5HOyNXr0HGlDTH2J6F9T1RiNf40Lbxowc3/Y=; b=T2X2WEhEYDzB4KCF3NNLk1RbecP/CBNASbCSi6U0fANam2DrhmN23OCzh5WtnZMoYa tHULQpFMEAP96ZF0hyW7wYTIABHjkwoP6bFDAiYQVR0nHt0mdYjeYJipXTT4lw4ZA9rz rL4s/xqQAxs6LM1iEUgQxtVBUiA83pNE1LvmA+POX/icF4kmTLKEaAqZ+kkHNl7OGG2I ySQO09ARkPtywvbZNyHUSkc//ymu1uaGjKyXeExaym1dUQwncFc0ZJyg+lehGhvmHdIp 2IT+4DwjwbD8dgjn9JXL9qOh5ONeTyhLMoj83rThazOl2zKvdDf+RMfjBhNzsMu+09v4 2yWA== |
| X-Gm-Message-State | AOAM533GOD2m3cQQKjf/Um/4SuJAIvS5rYNm/EvLFOOqIczjme2hEsnc Y0pUpyI/zuCZfo6AbuQxQfq/ewpICFbO48FU7Lxow5BSSIuOKQ== |
| X-Google-Smtp-Source | ABdhPJxG810TYTMEbEAQAFJWfuiis7RDfzqd2y9pQVymyudOkQydYB3qOmLK4xlyv8Mqkw6PLM34tscAKbtCUzLeXiI= |
| X-Received | by 2002:a02:85e1:: with SMTP id d88mr5486262jai.8.1598710997897; Sat, 29 Aug 2020 07:23:17 -0700 (PDT) |
| Received-SPF | pass client-ip=2607:f8b0:4864:20::d43; envelope-from=bruce.lilly@gmail.com; helo=mail-io1-xd43.google.com |
| X-detected-operating-system | by eggs.gnu.org: No matching host in p0f cache. That's all we know. |
| X-Spam_score_int | -20 |
| X-Spam_score | -2.1 |
| X-Spam_bar | -- |
| X-Spam_report | (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no |
| X-Spam_action | no action |
| X-Mailman-Approved-At | Sat, 29 Aug 2020 10:47:08 -0400 |
| X-BeenThere | bug-bash@gnu.org |
| X-Mailman-Version | 2.1.23 |
| Precedence | list |
| List-Id | Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org> |
| List-Unsubscribe | <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe> |
| List-Archive | <https://lists.gnu.org/archive/html/bug-bash> |
| List-Post | <mailto:bug-bash@gnu.org> |
| List-Help | <mailto:bug-bash-request@gnu.org?subject=help> |
| List-Subscribe | <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe> |
| X-Mailman-Original-Message-ID | <CAPyES363zNvUZHWo6imXOyC3UPU5FAbsyFGzWkcJMO-HBhT6gQ@mail.gmail.com> |
| Xref | csiph.com gnu.bash.bug:16841 |
Show key headers only | View raw
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: netbsd
Compiler: gcc
Compilation CFLAGS: -O2 -D_FORTIFY_SOURCE=2 -I/usr/include
-Wno-parentheses -Wno-format-security
uname output: NetBSD cq60-615dx.blilly.net 9.0 NetBSD 9.0 (GENERIC)
#0: Fri Feb 14 00:06:28 UTC 2020
mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/amd64/compile/GENERIC
amd64
Machine Type: x86_64--netbsd
Bash Version: 5.0
Patch Level: 17
Release Status: release
Description:
Bash parameter expansion (remove largest trailing match, remove
largest leading match, pattern replacement) does not work
Tested on OpenSUSE Leap 15.2, bash version 4.4.2.3(1)-release
(x86_64-suse-linux-gnu)
OpenBSD 6.7 bash version 5.0.17(1)-release (x86_64-unknown-openbsd6.7)
NetBSD 9.0 bash version 5.0.17(1)-release (x86_64--netbsd)
FreeBSD 12.1-STABLE bash version 5.0.18(2)-release (amd64-portbld-freebsd12.1)
Same results in all cases; this report posted from NetBSD 9.0.
As an example, consider constructing a path from components; the full
path should
have a single separator (slash), so any stray slashes at the tail of
the first part or the
start of the last part should be elided. There are many ways that
that can be done,
the "Repeat By" section demonstrates only a few examples.
Relevant manual sections are:
https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Shell-Parameter-Expansion
https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Pattern-Matching
Repeat-By:
$ bash shellbug
Running bash from /usr/pkg/bin/bash
Bash version 5.0.17(1) release GNU
dir=/foo/bar/baz/// separator1=/ separator2(octal escape)=\057
number0=* number1=+ pattern1=${number1}(${separator1})=+(/)
pattern2=${number0}([${separator2}])=*([\057]) base=///grimble/pritz
path=${dir%%${pattern1}}${separator1}${base##${pattern2}}=${dir%%+(/)}/${base##*([\057])}=/foo/bar/baz///////grimble/pritz
path=${dir/%${pattern1}/${separator1}}${base/#${pattern2}/}=${dir/%+(/)//}${base/#*([\057])/}=/foo/bar/baz//////grimble/pritz
Fix:
(demonstrates how a functioning shell handles exactly the same cases):
$ ksh93 shellbug
Running ksh93 from /usr/pkg/bin/ksh93
$Id: Version AJM 93u+ 2012-08-01 $
dir=/foo/bar/baz/// separator1=/ separator2(octal escape)=\057
number0=* number1=+ pattern1=${number1}(${separator1})=+(/)
pattern2=${number0}([${separator2}])=*([\057]) base=///grimble/pritz
path=${dir%%${pattern1}}${separator1}${base##${pattern2}}=${dir%%+(/)}/${base##*([\057])}=/foo/bar/baz/grimble/pritz
path=${dir/%${pattern1}/${separator1}}${base/#${pattern2}/}=${dir/%+(/)//}${base/#*([\057])/}=/foo/bar/baz/grimble/pritz
Back to gnu.bash.bug | Previous | Next | Find similar
Bash parameter expansion (remove largest trailing match, remove largest leading match, pattern replacement) does not work Bruce Lilly <bruce.lilly@gmail.com> - 2020-08-29 10:22 -0400
csiph-web