Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

THEGODDESSOFTHENETHASTWISTINGFINGERSANDHERVOICEISLIKEAJAVELININTHENIGHTDUDE


devel / comp.unix.shell / Re: Splitting in shell script - harder than it looks (Was: Trashy non-descriptive content of subject field deleted (post) refused by newsserver)

SubjectAuthor
* bind -x '"\er": trap '' 2; READLINE_LINE=$(percol_sel_log_history)hongy...@gmail.com
+- Re: bind -x '"\er": trap '' 2; READLINE_LINE=$(percol_sel_log_history)hongy...@gmail.com
`* Trashy non-descriptive content of subject field deleted (post refusedJanis Papanagnou
 `* Re: Trashy non-descriptive content of subject field deleted (posthongy...@gmail.com
  `* Re: Trashy non-descriptive content of subject field deleted (postJanis Papanagnou
   +- Re: Trashy non-descriptive content of subject field deleted (posthongy...@gmail.com
   +* Re: Trashy non-descriptive content of subject field deleted (post refused by newBen Bacarisse
   |`- Re: Trashy non-descriptive content of subject field deleted (posthongy...@gmail.com
   `* Splitting in shell script - harder than it looks (Was: Trashy non-descriptive coKenny McCormack
    +- Re: Splitting in shell script - harder than it looks (Was: Trashyhongy...@gmail.com
    `* Re: Splitting in shell script - harder than it looks (Was: TrashyJanis Papanagnou
     `* Re: Splitting in shell script - harder than it looks (Was: TrashyKenny McCormack
      `- Re: Splitting in shell script - harder than it looks (Was: TrashyJanis Papanagnou

1
bind -x '"\er": trap '' 2; READLINE_LINE=$(percol_sel_log_history) READLINE_POINT=; trap 2'

<432521e2-ff1e-4468-821f-f1c290560df5n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4303&group=comp.unix.shell#4303

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:ac8:7761:: with SMTP id h1mr2300386qtu.272.1630650369968;
Thu, 02 Sep 2021 23:26:09 -0700 (PDT)
X-Received: by 2002:a37:aa8f:: with SMTP id t137mr1945031qke.30.1630650369793;
Thu, 02 Sep 2021 23:26:09 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Thu, 2 Sep 2021 23:26:09 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=178.128.97.233; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 178.128.97.233
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <432521e2-ff1e-4468-821f-f1c290560df5n@googlegroups.com>
Subject: bind -x '"\er": trap '' 2; READLINE_LINE=$(percol_sel_log_history)
READLINE_POINT=; trap 2'
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Fri, 03 Sep 2021 06:26:09 +0000
Content-Type: text/plain; charset="UTF-8"
 by: hongy...@gmail.com - Fri, 3 Sep 2021 06:26 UTC

See here [1] for the code snippet used in one of my forked project:

if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then
# https://github.com/dvorka/hstr/blob/master/CONFIGURATION.md#bash-binding-hstr-to-keyboard-shortcut
# https://www.computerhope.com/unix/bash/bind.htm
#I'm still not so clear on whether the syntax is case sensitive.
bind -x '"\er": trap '' 2; READLINE_LINE=$(percol_sel_log_history) READLINE_POINT=; trap 2'

#bind -x '"\C-\M-R": trap '' 2; READLINE_LINE=$(percol_sel_log_master_history) READLINE_POINT=; trap 2'
#bind -x '"\C-\M-r": trap '' 2; READLINE_LINE=$(percol_sel_log_master_history) READLINE_POINT=; trap 2'
#bind -x '"\e\C-R": trap '' 2; READLINE_LINE=$(percol_sel_log_master_history) READLINE_POINT=; trap 2'
#bind -x '"\e\C-r": trap '' 2; READLINE_LINE=$(percol_sel_log_master_history) READLINE_POINT=; trap 2'
fi

I've 2 questions on the above code snippet:

1. For the short keys binding to bind command, is the character case-sensitive or not?
2. What does the ``READLINE_POINT='' used above do?

[1] https://github.com/hongyi-zhao/ariadne/blob/b094e0634c4d5890b5ca48fa0a0974adcbe177b0/ariadne.sh#L229

Regards,
HY

Re: bind -x '"\er": trap '' 2; READLINE_LINE=$(percol_sel_log_history) READLINE_POINT=; trap 2'

<e6e9758c-c9cb-4ee4-b616-9bfeed2a2051n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4304&group=comp.unix.shell#4304

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:622a:11ce:: with SMTP id n14mr2393133qtk.374.1630651561041;
Thu, 02 Sep 2021 23:46:01 -0700 (PDT)
X-Received: by 2002:a05:620a:149c:: with SMTP id w28mr1941856qkj.292.1630651560915;
Thu, 02 Sep 2021 23:46:00 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Thu, 2 Sep 2021 23:46:00 -0700 (PDT)
In-Reply-To: <432521e2-ff1e-4468-821f-f1c290560df5n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=60.249.28.132; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 60.249.28.132
References: <432521e2-ff1e-4468-821f-f1c290560df5n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e6e9758c-c9cb-4ee4-b616-9bfeed2a2051n@googlegroups.com>
Subject: Re: bind -x '"\er": trap '' 2; READLINE_LINE=$(percol_sel_log_history)
READLINE_POINT=; trap 2'
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Fri, 03 Sep 2021 06:46:01 +0000
Content-Type: text/plain; charset="UTF-8"
 by: hongy...@gmail.com - Fri, 3 Sep 2021 06:46 UTC

On Friday, September 3, 2021 at 2:26:12 PM UTC+8, hongy...@gmail.com wrote:
> See here [1] for the code snippet used in one of my forked project:
>
> if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then
> # https://github.com/dvorka/hstr/blob/master/CONFIGURATION.md#bash-binding-hstr-to-keyboard-shortcut
> # https://www.computerhope.com/unix/bash/bind.htm
> #I'm still not so clear on whether the syntax is case sensitive.
> bind -x '"\er": trap '' 2; READLINE_LINE=$(percol_sel_log_history) READLINE_POINT=; trap 2'
>
> #bind -x '"\C-\M-R": trap '' 2; READLINE_LINE=$(percol_sel_log_master_history) READLINE_POINT=; trap 2'
> #bind -x '"\C-\M-r": trap '' 2; READLINE_LINE=$(percol_sel_log_master_history) READLINE_POINT=; trap 2'
> #bind -x '"\e\C-R": trap '' 2; READLINE_LINE=$(percol_sel_log_master_history) READLINE_POINT=; trap 2'
> #bind -x '"\e\C-r": trap '' 2; READLINE_LINE=$(percol_sel_log_master_history) READLINE_POINT=; trap 2'
> fi
>
> I've 2 questions on the above code snippet:
>
> 1. For the short keys binding to bind command, is the character case-sensitive or not?
> 2. What does the ``READLINE_POINT='' used above do?

I tried with the following two bind commands, and they give the exactly same behavior:

bind -x '"\er": trap '' 2; READLINE_LINE=$(percol_sel_log_history) READLINE_POINT=; trap 2'
bind -x '"\er": trap '' 2; READLINE_LINE=$(percol_sel_log_history); READLINE_POINT=${#READLINE_LINE}; trap 2'

>
> [1] https://github.com/hongyi-zhao/ariadne/blob/b094e0634c4d5890b5ca48fa0a0974adcbe177b0/ariadne.sh#L229
>
> Regards,
> HY

Trashy non-descriptive content of subject field deleted (post refused by newsserver)

<sh02p7$ulb$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4307&group=comp.unix.shell#4307

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!I4G2pI/TjSgw9iO3pv/WTg.user.46.165.242.75.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Trashy non-descriptive content of subject field deleted (post refused
by newsserver)
Date: Sat, 4 Sep 2021 17:19:03 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sh02p7$ulb$1@gioia.aioe.org>
References: <432521e2-ff1e-4468-821f-f1c290560df5n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="31403"; posting-host="I4G2pI/TjSgw9iO3pv/WTg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
X-Notice: Filtered by postfilter v. 0.9.2
 by: Janis Papanagnou - Sat, 4 Sep 2021 15:19 UTC

On 03.09.2021 08:26, hongy...@gmail.com wrote:
> See here [1] for the code snippet used in one of my forked project:
>
> if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then

Given that SHELLOPTS is a colon-separated list this test appears to
be error prone.

Janis

Re: Trashy non-descriptive content of subject field deleted (post refused by newsserver)

<f00d94d4-9e18-4f38-afb5-bfceb44b8277n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4309&group=comp.unix.shell#4309

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:620a:81d:: with SMTP id s29mr5326161qks.301.1630802793053;
Sat, 04 Sep 2021 17:46:33 -0700 (PDT)
X-Received: by 2002:a05:6214:d8a:: with SMTP id e10mr6041524qve.52.1630802792913;
Sat, 04 Sep 2021 17:46:32 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Sat, 4 Sep 2021 17:46:32 -0700 (PDT)
In-Reply-To: <sh02p7$ulb$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=103.138.53.113; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 103.138.53.113
References: <432521e2-ff1e-4468-821f-f1c290560df5n@googlegroups.com> <sh02p7$ulb$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f00d94d4-9e18-4f38-afb5-bfceb44b8277n@googlegroups.com>
Subject: Re: Trashy non-descriptive content of subject field deleted (post
refused by newsserver)
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Sun, 05 Sep 2021 00:46:33 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 15
 by: hongy...@gmail.com - Sun, 5 Sep 2021 00:46 UTC

On Saturday, September 4, 2021 at 11:19:08 PM UTC+8, Janis Papanagnou wrote:
> On 03.09.2021 08:26, hongy...@gmail.com wrote:
> > See here [1] for the code snippet used in one of my forked project:
> >
> > if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then
> Given that SHELLOPTS is a colon-separated list this test appears to
> be error prone.

What is the special situation that caused its failure? It really works on my side now:

$ echo ${SHELLOPTS}
braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
$ [[ ${SHELLOPTS} =~ (vi|emacs) ]] && echo ok
ok

HY

Re: Trashy non-descriptive content of subject field deleted (post refused by newsserver)

<sh15aq$h5k$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4310&group=comp.unix.shell#4310

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!I4G2pI/TjSgw9iO3pv/WTg.user.46.165.242.75.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Trashy non-descriptive content of subject field deleted (post
refused by newsserver)
Date: Sun, 5 Sep 2021 03:08:42 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sh15aq$h5k$1@gioia.aioe.org>
References: <432521e2-ff1e-4468-821f-f1c290560df5n@googlegroups.com>
<sh02p7$ulb$1@gioia.aioe.org>
<f00d94d4-9e18-4f38-afb5-bfceb44b8277n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="17588"; posting-host="I4G2pI/TjSgw9iO3pv/WTg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
X-Notice: Filtered by postfilter v. 0.9.2
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Sun, 5 Sep 2021 01:08 UTC

On 05.09.2021 02:46, hongy...@gmail.com wrote:
> On Saturday, September 4, 2021 at 11:19:08 PM UTC+8, Janis Papanagnou wrote:
>> On 03.09.2021 08:26, hongy...@gmail.com wrote:
>>> See here [1] for the code snippet used in one of my forked project:
>>>
>>> if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then
>> Given that SHELLOPTS is a colon-separated list this test appears to
>> be error prone.
>
> What is the special situation that caused its failure?

If, for example, "vi" is or becomes part of any of the shell option
substrings.

$ SHELLOPTS=priviledged
$ [[ ${SHELLOPTS} =~ (vi|emacs) ]] && echo ok
ok

> It really works on my side now:

By accident.

The way you do the test is inherently broken.

If you want to test the SHELLOPTS components against two constants you
have to either split SHELLOPTS and compare the parts individually or
add the delimiters (considering not only the colons but also the start
and end of a sting) to the pattern expression.

Janis

>
> $ echo ${SHELLOPTS}
> braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
> $ [[ ${SHELLOPTS} =~ (vi|emacs) ]] && echo ok
> ok
>
> HY
>

Re: Trashy non-descriptive content of subject field deleted (post refused by newsserver)

<fe7e259d-0c64-431f-a7e7-b960bce23fe9n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4311&group=comp.unix.shell#4311

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a37:40d3:: with SMTP id n202mr5219086qka.357.1630806670921;
Sat, 04 Sep 2021 18:51:10 -0700 (PDT)
X-Received: by 2002:ac8:44aa:: with SMTP id a10mr5623493qto.63.1630806670643;
Sat, 04 Sep 2021 18:51:10 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Sat, 4 Sep 2021 18:51:10 -0700 (PDT)
In-Reply-To: <sh15aq$h5k$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=103.138.53.187; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 103.138.53.187
References: <432521e2-ff1e-4468-821f-f1c290560df5n@googlegroups.com>
<sh02p7$ulb$1@gioia.aioe.org> <f00d94d4-9e18-4f38-afb5-bfceb44b8277n@googlegroups.com>
<sh15aq$h5k$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <fe7e259d-0c64-431f-a7e7-b960bce23fe9n@googlegroups.com>
Subject: Re: Trashy non-descriptive content of subject field deleted (post
refused by newsserver)
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Sun, 05 Sep 2021 01:51:10 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 39
 by: hongy...@gmail.com - Sun, 5 Sep 2021 01:51 UTC

On Sunday, September 5, 2021 at 9:08:49 AM UTC+8, Janis Papanagnou wrote:
> On 05.09.2021 02:46, hongy...@gmail.com wrote:
> > On Saturday, September 4, 2021 at 11:19:08 PM UTC+8, Janis Papanagnou wrote:
> >> On 03.09.2021 08:26, hongy...@gmail.com wrote:
> >>> See here [1] for the code snippet used in one of my forked project:
> >>>
> >>> if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then
> >> Given that SHELLOPTS is a colon-separated list this test appears to
> >> be error prone.
> >
> > What is the special situation that caused its failure?
> If, for example, "vi" is or becomes part of any of the shell option
> substrings.
>
> $ SHELLOPTS=priviledged
> $ [[ ${SHELLOPTS} =~ (vi|emacs) ]] && echo ok
> ok
> > It really works on my side now:
> By accident.
>
> The way you do the test is inherently broken.
>
> If you want to test the SHELLOPTS components against two constants you
> have to either split SHELLOPTS and compare the parts individually or
> add the delimiters (considering not only the colons but also the start
> and end of a sting) to the pattern expression.

Got it. Now I changed to the following pattern:

$ set -o | egrep '\bon$' | egrep -q '^(vi|emacs)\b'
> Janis
> >
> > $ echo ${SHELLOPTS}
> > braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
> > $ [[ ${SHELLOPTS} =~ (vi|emacs) ]] && echo ok
> > ok
> >
> > HY
> >

Re: Trashy non-descriptive content of subject field deleted (post refused by newsserver)

<87zgsrn5xj.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4312&group=comp.unix.shell#4312

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.unix.shell
Subject: Re: Trashy non-descriptive content of subject field deleted (post refused by newsserver)
Date: Sun, 05 Sep 2021 02:54:00 +0100
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <87zgsrn5xj.fsf@bsb.me.uk>
References: <432521e2-ff1e-4468-821f-f1c290560df5n@googlegroups.com>
<sh02p7$ulb$1@gioia.aioe.org>
<f00d94d4-9e18-4f38-afb5-bfceb44b8277n@googlegroups.com>
<sh15aq$h5k$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="6fb1df09cdcd2ce174a1b9ab2833b323";
logging-data="26504"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+gSfJNgKyX9DE4jxtn0zsUc7TqevHrXjA="
Cancel-Lock: sha1:qSFFPuxJo+LsDZQmmyQpUTBgFC8=
sha1:/TLQwmRGaGSotUF4IUlGiDEhV74=
X-BSB-Auth: 1.7cb0947965e265671b03.20210905025400BST.87zgsrn5xj.fsf@bsb.me.uk
 by: Ben Bacarisse - Sun, 5 Sep 2021 01:54 UTC

Janis Papanagnou <janis_papanagnou@hotmail.com> writes:

> On 05.09.2021 02:46, hongy...@gmail.com wrote:
>> On Saturday, September 4, 2021 at 11:19:08 PM UTC+8, Janis Papanagnou wrote:
>>> On 03.09.2021 08:26, hongy...@gmail.com wrote:
>>>> See here [1] for the code snippet used in one of my forked project:
>>>>
>>>> if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then
>>> Given that SHELLOPTS is a colon-separated list this test appears to
>>> be error prone.
>>
>> What is the special situation that caused its failure?
>
> If, for example, "vi" is or becomes part of any of the shell option
> substrings.
>
> $ SHELLOPTS=priviledged
> $ [[ ${SHELLOPTS} =~ (vi|emacs) ]] && echo ok
> ok
>
>> It really works on my side now:
>
> By accident.
>
> The way you do the test is inherently broken.
>
> If you want to test the SHELLOPTS components against two constants you
> have to either split SHELLOPTS and compare the parts individually or
> add the delimiters (considering not only the colons but also the start
> and end of a sting) to the pattern expression.

The other way is to add the delimiters to both sides:

[[ ":$SHELLOPTS:" =~ :(vi|emacs): ]]

--
Ben.

Re: Trashy non-descriptive content of subject field deleted (post refused by newsserver)

<94b74f2d-a967-4341-84c0-688a27259cbfn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4314&group=comp.unix.shell#4314

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a0c:f88f:: with SMTP id u15mr6185487qvn.38.1630807124232;
Sat, 04 Sep 2021 18:58:44 -0700 (PDT)
X-Received: by 2002:a05:620a:2094:: with SMTP id e20mr5326987qka.171.1630807124115;
Sat, 04 Sep 2021 18:58:44 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Sat, 4 Sep 2021 18:58:43 -0700 (PDT)
In-Reply-To: <87zgsrn5xj.fsf@bsb.me.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=103.138.53.245; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 103.138.53.245
References: <432521e2-ff1e-4468-821f-f1c290560df5n@googlegroups.com>
<sh02p7$ulb$1@gioia.aioe.org> <f00d94d4-9e18-4f38-afb5-bfceb44b8277n@googlegroups.com>
<sh15aq$h5k$1@gioia.aioe.org> <87zgsrn5xj.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <94b74f2d-a967-4341-84c0-688a27259cbfn@googlegroups.com>
Subject: Re: Trashy non-descriptive content of subject field deleted (post
refused by newsserver)
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Sun, 05 Sep 2021 01:58:44 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 37
 by: hongy...@gmail.com - Sun, 5 Sep 2021 01:58 UTC

On Sunday, September 5, 2021 at 9:54:05 AM UTC+8, Ben Bacarisse wrote:
> Janis Papanagnou <janis_pa...@hotmail.com> writes:
>
> > On 05.09.2021 02:46, hongy...@gmail.com wrote:
> >> On Saturday, September 4, 2021 at 11:19:08 PM UTC+8, Janis Papanagnou wrote:
> >>> On 03.09.2021 08:26, hongy...@gmail.com wrote:
> >>>> See here [1] for the code snippet used in one of my forked project:
> >>>>
> >>>> if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then
> >>> Given that SHELLOPTS is a colon-separated list this test appears to
> >>> be error prone.
> >>
> >> What is the special situation that caused its failure?
> >
> > If, for example, "vi" is or becomes part of any of the shell option
> > substrings.
> >
> > $ SHELLOPTS=priviledged
> > $ [[ ${SHELLOPTS} =~ (vi|emacs) ]] && echo ok
> > ok
> >
> >> It really works on my side now:
> >
> > By accident.
> >
> > The way you do the test is inherently broken.
> >
> > If you want to test the SHELLOPTS components against two constants you
> > have to either split SHELLOPTS and compare the parts individually or
> > add the delimiters (considering not only the colons but also the start
> > and end of a sting) to the pattern expression.
> The other way is to add the delimiters to both sides:
>
> [[ ":$SHELLOPTS:" =~ :(vi|emacs): ]]

Thank you for the clever solution
HY

Splitting in shell script - harder than it looks (Was: Trashy non-descriptive content of subject field deleted (post) refused by newsserver)

<sh18ng$1mfde$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4315&group=comp.unix.shell#4315

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Splitting in shell script - harder than it looks (Was: Trashy non-descriptive content of subject field deleted (post)
refused by newsserver)
Date: Sun, 5 Sep 2021 02:06:40 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <sh18ng$1mfde$1@news.xmission.com>
References: <432521e2-ff1e-4468-821f-f1c290560df5n@googlegroups.com> <sh02p7$ulb$1@gioia.aioe.org> <f00d94d4-9e18-4f38-afb5-bfceb44b8277n@googlegroups.com> <sh15aq$h5k$1@gioia.aioe.org>
Injection-Date: Sun, 5 Sep 2021 02:06:40 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="1785262"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Sun, 5 Sep 2021 02:06 UTC

In article <sh15aq$h5k$1@gioia.aioe.org>,
Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
....
>The way you do the test is inherently broken.
>
>If you want to test the SHELLOPTS components against two constants you
>have to either split SHELLOPTS and compare the parts individually or
>add the delimiters (considering not only the colons but also the start
>and end of a sting) to the pattern expression.

Which is surprisingly hard to do (correctly). Splitting strings on
delimiters is not something shell script natively does. Yes, it can be
kludged, but it is harder than it ought to be. Messing around with IFS
seems to be the way, but doing so is hazardous to your health.

If I were doing this, I'd probably end up doing:

$ gawk -F: '{ for (i=1; i<=NF; i++) if ($i == "vi") exit 1 }' <<< "$SHELLOPTS" ||
echo "Yes, vi is set!"
$

Note: Nothing gawk-specific, but of course, both <<< and SHELLOPS are
bash-specific.

--
After 4 years of disastrous screwups, Trump now favors 3 policies that I support:
1) $2K/pp stimulus money. Who doesn't want more money?
2) Water pressure. My shower doesn't work very well; I want Donnie to come fix it.
3) Repeal of Section 230. This will lead to the demise of Face/Twit/Gram. Yey!

Re: Splitting in shell script - harder than it looks (Was: Trashy non-descriptive content of subject field deleted (post) refused by newsserver)

<699f06fe-1e15-40a5-a8bd-f17af433f888n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4316&group=comp.unix.shell#4316

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:ad4:5a06:: with SMTP id ei6mr6266767qvb.21.1630809501559;
Sat, 04 Sep 2021 19:38:21 -0700 (PDT)
X-Received: by 2002:a37:2cc4:: with SMTP id s187mr5334572qkh.407.1630809501352;
Sat, 04 Sep 2021 19:38:21 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Sat, 4 Sep 2021 19:38:21 -0700 (PDT)
In-Reply-To: <sh18ng$1mfde$1@news.xmission.com>
Injection-Info: google-groups.googlegroups.com; posting-host=103.138.53.177; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 103.138.53.177
References: <432521e2-ff1e-4468-821f-f1c290560df5n@googlegroups.com>
<sh02p7$ulb$1@gioia.aioe.org> <f00d94d4-9e18-4f38-afb5-bfceb44b8277n@googlegroups.com>
<sh15aq$h5k$1@gioia.aioe.org> <sh18ng$1mfde$1@news.xmission.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <699f06fe-1e15-40a5-a8bd-f17af433f888n@googlegroups.com>
Subject: Re: Splitting in shell script - harder than it looks (Was: Trashy
non-descriptive content of subject field deleted (post) refused by newsserver)
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Sun, 05 Sep 2021 02:38:21 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 34
 by: hongy...@gmail.com - Sun, 5 Sep 2021 02:38 UTC

On Sunday, September 5, 2021 at 10:06:45 AM UTC+8, Kenny McCormack wrote:
> In article <sh15aq$h5k$1...@gioia.aioe.org>,
> Janis Papanagnou <janis_pa...@hotmail.com> wrote:
> ...
> >The way you do the test is inherently broken.
> >
> >If you want to test the SHELLOPTS components against two constants you
> >have to either split SHELLOPTS and compare the parts individually or
> >add the delimiters (considering not only the colons but also the start
> >and end of a sting) to the pattern expression.
> Which is surprisingly hard to do (correctly). Splitting strings on
> delimiters is not something shell script natively does. Yes, it can be
> kludged, but it is harder than it ought to be. Messing around with IFS
> seems to be the way, but doing so is hazardous to your health.
>
> If I were doing this, I'd probably end up doing:
>
> $ gawk -F: '{ for (i=1; i<=NF; i++) if ($i == "vi") exit 1 }' <<< "$SHELLOPTS" ||
> echo "Yes, vi is set!"
> $

Also, the following one:

$ tr ':' '\n' <<< "$SHELLOPTS" | egrep '^(vi|emacs)\b'
emacs


> Note: Nothing gawk-specific, but of course, both <<< and SHELLOPS are
> bash-specific.
>
> --
> After 4 years of disastrous screwups, Trump now favors 3 policies that I support:
> 1) $2K/pp stimulus money. Who doesn't want more money?
> 2) Water pressure. My shower doesn't work very well; I want Donnie to come fix it.
> 3) Repeal of Section 230. This will lead to the demise of Face/Twit/Gram. Yey!

Re: Splitting in shell script - harder than it looks (Was: Trashy non-descriptive content of subject field deleted (post) refused by newsserver)

<sh2a25$tnn$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4317&group=comp.unix.shell#4317

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!I4G2pI/TjSgw9iO3pv/WTg.user.46.165.242.75.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Splitting in shell script - harder than it looks (Was: Trashy
non-descriptive content of subject field deleted (post) refused by
newsserver)
Date: Sun, 5 Sep 2021 13:35:33 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sh2a25$tnn$1@gioia.aioe.org>
References: <432521e2-ff1e-4468-821f-f1c290560df5n@googlegroups.com>
<sh02p7$ulb$1@gioia.aioe.org>
<f00d94d4-9e18-4f38-afb5-bfceb44b8277n@googlegroups.com>
<sh15aq$h5k$1@gioia.aioe.org> <sh18ng$1mfde$1@news.xmission.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="30455"; posting-host="I4G2pI/TjSgw9iO3pv/WTg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
X-Notice: Filtered by postfilter v. 0.9.2
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Sun, 5 Sep 2021 11:35 UTC

On 05.09.2021 04:06, Kenny McCormack wrote:
> In article <sh15aq$h5k$1@gioia.aioe.org>,
> Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
> ...
>> The way you do the test is inherently broken.
>>
>> If you want to test the SHELLOPTS components against two constants you
>> have to either split SHELLOPTS and compare the parts individually or
>> add the delimiters (considering not only the colons but also the start
>> and end of a sting) to the pattern expression.
>
> Which is surprisingly hard to do (correctly). Splitting strings on
> delimiters is not something shell script natively does. Yes, it can be
> kludged, but it is harder than it ought to be. Messing around with IFS
> seems to be the way, but doing so is hazardous to your health.

Actually adding the colon to the pattern that I suggested I consider
quite simple and straightforward, and Ben's hint to also add colons
to the variable on the left to prevent complex patterns on the right
makes it, so I think, a perfect shell code pattern.

With modern shells (that the OP also uses) we can also use other code
patterns to address that splitting task, for example using ${v//p/r}
as in

grep vi <<EOT
${SHELLOPTS//:/
} EOT

>
> If I were doing this, I'd probably end up doing:
>
> $ gawk -F: '{ for (i=1; i<=NF; i++) if ($i == "vi") exit 1 }' <<< "$SHELLOPTS" ||
> echo "Yes, vi is set!"
> $

An advantage here is that it's obvious to programmers (also of other
languages) what's going on, less obscure than shell code.

I'm a big fan of awk, nonetheless I try to minimize awk/sh transitions
if possible, and resort to pure awk or pure sh code patterns unless
these are overly clumsy.

Janis

Re: Splitting in shell script - harder than it looks (Was: Trashy non-descriptive content of subject field deleted (post) refused by newsserver)

<sh2feo$1n1v9$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4318&group=comp.unix.shell#4318

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: Splitting in shell script - harder than it looks (Was: Trashy
non-descriptive content of subject field deleted (post) refused by
newsserver)
Date: Sun, 5 Sep 2021 13:07:36 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <sh2feo$1n1v9$1@news.xmission.com>
References: <432521e2-ff1e-4468-821f-f1c290560df5n@googlegroups.com> <sh15aq$h5k$1@gioia.aioe.org> <sh18ng$1mfde$1@news.xmission.com> <sh2a25$tnn$1@gioia.aioe.org>
Injection-Date: Sun, 5 Sep 2021 13:07:36 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="1804265"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Sun, 5 Sep 2021 13:07 UTC

In article <sh2a25$tnn$1@gioia.aioe.org>,
Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
>On 05.09.2021 04:06, Kenny McCormack wrote:
>> In article <sh15aq$h5k$1@gioia.aioe.org>,
>> Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
>> ...
>>> The way you do the test is inherently broken.
>>>
>>> If you want to test the SHELLOPTS components against two constants you
>>> have to either split SHELLOPTS and compare the parts individually or
>>> add the delimiters (considering not only the colons but also the start
>>> and end of a sting) to the pattern expression.
>>
>> Which is surprisingly hard to do (correctly). Splitting strings on
>> delimiters is not something shell script natively does. Yes, it can be
>> kludged, but it is harder than it ought to be. Messing around with IFS
>> seems to be the way, but doing so is hazardous to your health.
>
>Actually adding the colon to the pattern that I suggested I consider
>quite simple and straightforward, and Ben's hint to also add colons
>to the variable on the left to prevent complex patterns on the right
>makes it, so I think, a perfect shell code pattern.

You are totally missing the point.

--
He must be a Muslim. He's got three wives and he doesn't drink.

Re: Splitting in shell script - harder than it looks (Was: Trashy non-descriptive content of subject field deleted (post) refused by newsserver)

<sh2koc$1f5b$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4319&group=comp.unix.shell#4319

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!I4G2pI/TjSgw9iO3pv/WTg.user.46.165.242.75.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Splitting in shell script - harder than it looks (Was: Trashy
non-descriptive content of subject field deleted (post) refused by
newsserver)
Date: Sun, 5 Sep 2021 16:38:03 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sh2koc$1f5b$1@gioia.aioe.org>
References: <432521e2-ff1e-4468-821f-f1c290560df5n@googlegroups.com>
<sh15aq$h5k$1@gioia.aioe.org> <sh18ng$1mfde$1@news.xmission.com>
<sh2a25$tnn$1@gioia.aioe.org> <sh2feo$1n1v9$1@news.xmission.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="48299"; posting-host="I4G2pI/TjSgw9iO3pv/WTg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
X-Enigmail-Draft-Status: N1110
X-Notice: Filtered by postfilter v. 0.9.2
 by: Janis Papanagnou - Sun, 5 Sep 2021 14:38 UTC

On 05.09.2021 15:07, Kenny McCormack wrote:
> In article <sh2a25$tnn$1@gioia.aioe.org>,
> Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
>> On 05.09.2021 04:06, Kenny McCormack wrote:
>>> In article <sh15aq$h5k$1@gioia.aioe.org>,
>>> Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
>>> ...
>>>> The way you do the test is inherently broken.
>>>>
>>>> If you want to test the SHELLOPTS components against two constants you
>>>> have to either split SHELLOPTS and compare the parts individually or
>>>> add the delimiters (considering not only the colons but also the start
>>>> and end of a sting) to the pattern expression.
>>>
>>> Which is surprisingly hard to do (correctly). Splitting strings on
>>> delimiters is not something shell script natively does. Yes, it can be
>>> kludged, but it is harder than it ought to be. Messing around with IFS
>>> seems to be the way, but doing so is hazardous to your health.
>>
>> Actually adding the colon to the pattern that I suggested I consider
>> quite simple and straightforward, and Ben's hint to also add colons
>> to the variable on the left to prevent complex patterns on the right
>> makes it, so I think, a perfect shell code pattern.
>
> You are totally missing the point.

Maybe. And maybe it's not worth discussing since you don't point out
what it actually is. (If you change your mind, you're welcome.)

I see two views in the discussion; one, the solution-oriented, two,
the narrower IFS based argument. I had been taking the first path.
If I should make a statement about the second view - expressed in
your statement
"Splitting strings on delimiters is not something shell script
natively does"
then I have to disagree with you. Here the showcase in ksh (I'm sure
bash supports similar features and options):

$ x=abc:def:ghi:jkl
$ IFS=: read -A a <<< $x
$ printf "%s\n" "${a[@]}"
abc
def
ghi
jkl

No "messing around", a clear field separator oriented pattern. One
can also write a loop (as in your awk suggestion), or just use grep.

YMMV.

N.B. Of course awk FS is more powerful since it supports regexps,
but this is neither requested here nore the topic.

Janis

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor