Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #16857

Re: Bash parameter expansion (remove largest trailing match, remove largest leading match, pattern replacement) does not work

Path csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
From Koichi Murase <myoga.murase@gmail.com>
Newsgroups gnu.bash.bug
Subject Re: Bash parameter expansion (remove largest trailing match, remove largest leading match, pattern replacement) does not work
Date Sun, 30 Aug 2020 05:53:20 +0900
Lines 74
Approved bug-bash@gnu.org
Message-ID <mailman.1739.1598734418.2469.bug-bash@gnu.org> (permalink)
References <CAPyES363zNvUZHWo6imXOyC3UPU5FAbsyFGzWkcJMO-HBhT6gQ@mail.gmail.com> <CAFLRLk_k+J3-Nt9UJ4Fb8c-RewPnVjf_b=ShqGGASG0GmREAhg@mail.gmail.com> <CAPyES3685SjyZfrL+M_56wGqxvh=N9xNchWJ1xqMSrmmEJb9ww@mail.gmail.com> <CAFLRLk9CBn1CUchi5tHmZ7FitWWpLaVc-Sxyr7=AuGRAQXWe9Q@mail.gmail.com> <CAPyES37OZ-TAjmxRp72dv97eKPzNes=__QqnBHuEK+rK78QSSg@mail.gmail.com> <CAFLRLk-WondkFshbc5=vF=20dViDyn20E7eps3rMJaog4ag7Yg@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 1598734419 3856 209.51.188.17 (29 Aug 2020 20:53:39 GMT)
X-Complaints-To action@cs.stanford.edu
Cc bug-bash@gnu.org
To Bruce Lilly <bruce.lilly@gmail.com>
Envelope-to bug-bash@gnu.org
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zhWfcH8BYRt788qxEqyQAEgq8K03ymlHihgLKh19L2Q=; b=l+zXOAyXFVTrIy6qF/tFec23iHeZoFT+bxfmYgw8ThKSl+hCD0hPiei9bAvaaudxzH Mn3up4lN6IVAjDald/tcraucfmS0Equo+oGR25TmFfnHRi+nCcGm4OyRBuj35/iGqupu WHDAp26t94UZ4+ZcY1UtQopQoASMcqVyhVInOAygNrnWp6y9n02zEMl06etsqvQsdPB5 zXlEGQ7bm9P6LADZG/yCfZbHhvOadensH4nXzvOopcQbjADUgih5Ur1vZNE4iz/nAS81 VUu/2/OtZXryoLCb0TAm2Tdb8G7jk0NCjsAHSioaU15aiz7+EvAijByFvd3tgQ9PufMS 95AA==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zhWfcH8BYRt788qxEqyQAEgq8K03ymlHihgLKh19L2Q=; b=ZNr49240QP7CIhGo3oNN2d/27nynwkv9vmxB2PpT2SO+dMqHqrRqEo5QE+Wp4/IOv6 U6GNefluszy37tKd1f1ae7QZcTlxABuM7Py71bCuts111J3P5nBopMffQdr1M2ww7hi5 OyH+/PrZQ2RcwVSuASr2HOSf6BvDTpt5BTfgHQIVqBuubIAJO9xIxz7utNet1e3tBg8L IIKSZR/oUfMHQTqnniKHUHXjng6V2dtruebRPSaUIok7A8qqzq/AEsgKscXmsgybflF5 XpMVN2LF4Y1ms5yjeOLUcjTzu9a5WwshtSG23mvwcugzeLH1vQsp2lPHArYUee5ZDaWf IOIQ==
X-Gm-Message-State AOAM532guBfH+K2LIOhnXQvEpeSi3LYS1LVczBqAD65XAvsy4CmKHdnQ tzW9NmpvNnlhDNxu6+OWwFuRDse+iLnijCRcQtY=
X-Google-Smtp-Source ABdhPJxvHU/8IQfj/x2wSl8UrftwrcmYESLWOy3sxBm1GHComYDfT+tVWz1/EI1PTKt9+UUX0p9qMPbTrWoGVeMBPwg=
X-Received by 2002:a17:906:957:: with SMTP id j23mr4977043ejd.344.1598734412100; Sat, 29 Aug 2020 13:53:32 -0700 (PDT)
In-Reply-To <CAPyES37OZ-TAjmxRp72dv97eKPzNes=__QqnBHuEK+rK78QSSg@mail.gmail.com>
Received-SPF pass client-ip=2a00:1450:4864:20::636; envelope-from=myoga.murase@gmail.com; helo=mail-ej1-x636.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-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 <CAFLRLk-WondkFshbc5=vF=20dViDyn20E7eps3rMJaog4ag7Yg@mail.gmail.com>
X-Mailman-Original-References <CAPyES363zNvUZHWo6imXOyC3UPU5FAbsyFGzWkcJMO-HBhT6gQ@mail.gmail.com> <CAFLRLk_k+J3-Nt9UJ4Fb8c-RewPnVjf_b=ShqGGASG0GmREAhg@mail.gmail.com> <CAPyES3685SjyZfrL+M_56wGqxvh=N9xNchWJ1xqMSrmmEJb9ww@mail.gmail.com> <CAFLRLk9CBn1CUchi5tHmZ7FitWWpLaVc-Sxyr7=AuGRAQXWe9Q@mail.gmail.com> <CAPyES37OZ-TAjmxRp72dv97eKPzNes=__QqnBHuEK+rK78QSSg@mail.gmail.com>
Xref csiph.com gnu.bash.bug:16857

Show key headers only | View raw


2020-08-30 4:54 Bruce Lilly <bruce.lilly@gmail.com>:
> On Sat, Aug 29, 2020, 15:40 Koichi Murase <myoga.murase@gmail.com> wrote:
>> Don't worry.  In this case, the GPL doesn't apply.  Please read the
>> following Q&A.
>>
>> https://www.gnu.org/licenses/gpl-faq.en.html#IfInterpreterIsGPL
>>
>> Even if your original `shellbug' is licensed under something other,
>> and it prohibits to make it public, you can still create another
>> script to reproduce the same issue.  [...]

I'm sorry if I have confused you, but first, let me clarify that I
meant by `create another script' that you can create a completely new
script from scratch instead of extracting the relevant part of the
original script.

> It's a bit more complicated than that; if, for example, some excerpt
> ended up in regression tests, there would be a question about
> whether or not there was a copyright violation.  As I understand the
> GPL (IANAL), it requires all parts of a "work" to be GPL'd, and that
> wouldn't be possible for any parts of the script that ended up in
> bash regression tests.

That's an interesting discussion.  I don't know how you define the
"work", but basically GPL only affects the derivative
programs/software but not all the "work" including the output of the
programs or the knowledge obtained in running/developing the code.

How about thinking in this way: You have gotten the knowledge that the
parameter expansions do not behave as you expected, and that knowledge
is not licensed by GPL.  Then you create a new script from scratch
based on the knowledge by trying to encode the idea directly and not
to be affected by the style of the original script as much as
possible.  I don't know but something like this reduced case:

  text=AABBCC patA='*(A)' patC='+(C)'
  echo "${text##$patA}, ${text%%$patC}"

I believe this shouldn't be considered GPL'd.  Otherwise, anyone who
read a GPL code in the past cannot write any non-GPL programs because
one cannot prove the experience of reading the GPL code doesn't affect
any code that he/she writes thereafter.  I sometimes hear that someone
avoids hiring programmers who have read a GPL code in the past for
defensive purposes, but I believe it's a matter of degree.

2020-08-30 5:07 Bruce Lilly <bruce.lilly@gmail.com>:
> That's surprising, as octal and hexadecimal escapes are fairly
> common.

Yes, I know that it is confusing to those who are familiar with modern
Perl-style regular expressions.  But historically, POSIX regular
expressions do not support the backslash escape sequences in bracket
expressions `[...]'.  The backslash escape sequences in bracket
expressions were the extension historically.  As far as I know, in
POSIX, only awk supports backslash sequences in regular expressions.

> Yes, I'm still looking into that (along with updating a couple of
> FreeBSD machines, eating lunch, and monitoring a couple of
> downloads).  I'll obviously have to wrap the "shopt" bit in a
> wrapper; is there some minimum bash version that supports it?

Bash 2.02 supports `shopt -s extglob', so you can assume every Bash
has the support.  If you are still failing to get an expected
behavior, you can just put the line `shopt -s extglob' in the
beginning of the script.  In the case of the above mentioned reduced
case, you can write like this:

  shopt -s extglob
  text=AABBCC patA='*(A)' patC='+(C)'
  echo "${text##$patA}, ${text%%$patC}"

--
Koichi

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: Bash parameter expansion (remove largest trailing match, remove largest leading match, pattern replacement) does not work Koichi Murase <myoga.murase@gmail.com> - 2020-08-30 05:53 +0900

csiph-web