Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

It's ten o'clock; do you know where your processes are?


devel / comp.unix.shell / Re: shellcheck: What does this mean?

SubjectAuthor
* shellcheck: What does this mean?Kenny McCormack
+* Re: shellcheck: What does this mean?Janis Papanagnou
|`* Re: shellcheck: What does this mean?Kenny McCormack
| `- Re: shellcheck: What does this mean?Janis Papanagnou
+- Re: shellcheck: What does this mean?Oğuz
`- Re: shellcheck: What does this mean?Léa Gris

1
shellcheck: What does this mean?

<sn9igd$r24n$1@news.xmission.com>

 copy mid

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

 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: shellcheck: What does this mean?
Date: Sat, 20 Nov 2021 01:20:13 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <sn9igd$r24n$1@news.xmission.com>
Injection-Date: Sat, 20 Nov 2021 01:20:13 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="886935"; 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 - Sat, 20 Nov 2021 01:20 UTC

I use shellcheck to check over my bash shell scripts. Most of what it
generates is noise, but every so often, it produces something useful -
something that should be fixed/cleaned up.

I recently added some code to the script and ran shellcheck on it, and it
generated the output below:

--- Cut here ---
In myScript line 145:
[[ "$REPLY" =~ ^\^ ]] && REPLY="title not like '%${REPLY:1}%'"
^-- SC1001: This \^ will be a regular '^' in this context.
^-- SC2089: Quotes/backslashes will be treated literally. Use an array.
--- Cut here ---

The intent is to check to see if $REPLY starts with a ^ and if so, change
it to the indicated string (yes, I am building up a SQL query). In my
testing, I determined that the right syntax in a Bash =~ test, to check for
a leading ^, is ^\^. So, what is the SC1001 complaining about? Isn't that
the right syntax to use?

Second, I don't understand the second error at all. What does "Use an
array" mean?

Note that the script works fine. There's nothing really wrong with it at all.

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/EternalFlame

Re: shellcheck: What does this mean?

<sn9ko9$g1n$1@dont-email.me>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: shellcheck: What does this mean?
Date: Sat, 20 Nov 2021 02:58:32 +0100
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <sn9ko9$g1n$1@dont-email.me>
References: <sn9igd$r24n$1@news.xmission.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 20 Nov 2021 01:58:33 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="6070e611aa33f12c92f1b423300562a0";
logging-data="16439"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+vW1gtwnxljsiAwptvbzty"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:r8Pm1FmubDp3QjSFn7nyFsHsMWs=
In-Reply-To: <sn9igd$r24n$1@news.xmission.com>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Sat, 20 Nov 2021 01:58 UTC

On 20.11.2021 02:20, Kenny McCormack wrote:
> I use shellcheck to check over my bash shell scripts. Most of what it
> generates is noise, but every so often, it produces something useful -
> something that should be fixed/cleaned up.
>
> I recently added some code to the script and ran shellcheck on it, and it
> generated the output below:
>
> --- Cut here ---
> In myScript line 145:
> [[ "$REPLY" =~ ^\^ ]] && REPLY="title not like '%${REPLY:1}%'"
> ^-- SC1001: This \^ will be a regular '^' in this context.
> ^-- SC2089: Quotes/backslashes will be treated literally. Use an array.
> --- Cut here ---
>
> The intent is to check to see if $REPLY starts with a ^ and if so, change
> it to the indicated string (yes, I am building up a SQL query). In my
> testing, I determined that the right syntax in a Bash =~ test, to check for
> a leading ^, is ^\^. So, what is the SC1001 complaining about? Isn't that
> the right syntax to use?

My interpretation is that ^^ is sufficient since there's just one
single ^ to indicate the start of the line and the second ^ thus
not interpreted as another start of line but taken literally.
I read the message just as suggestion to simplify the expression.

Apropos simplifying; I'd probably use the simpler shell patterns
here [[ $REPLY == ^* ]] && ... instead of regexp (looks more
straightforward to me without explicit anchor; YMMV).

>
> Second, I don't understand the second error at all. What does "Use an
> array" mean?

The tool seems to have got confused and provides a suggestion for
a non-existing problem, maybe?

>
> Note that the script works fine. There's nothing really wrong with it at all.

Looks quite fine to me.

Janis

Re: shellcheck: What does this mean?

<f881e22b-fc8b-4134-9976-2329fd07076dn@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:620a:f8b:: with SMTP id b11mr34186033qkn.81.1637387388149;
Fri, 19 Nov 2021 21:49:48 -0800 (PST)
X-Received: by 2002:a05:6214:d0e:: with SMTP id 14mr80022552qvh.10.1637387387961;
Fri, 19 Nov 2021 21:49:47 -0800 (PST)
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: Fri, 19 Nov 2021 21:49:47 -0800 (PST)
In-Reply-To: <sn9igd$r24n$1@news.xmission.com>
Injection-Info: google-groups.googlegroups.com; posting-host=78.165.5.146; posting-account=RbOzpwoAAACSDI6OO1wVarfPakNstxUl
NNTP-Posting-Host: 78.165.5.146
References: <sn9igd$r24n$1@news.xmission.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f881e22b-fc8b-4134-9976-2329fd07076dn@googlegroups.com>
Subject: Re: shellcheck: What does this mean?
From: oguzisma...@gmail.com (Oğuz)
Injection-Date: Sat, 20 Nov 2021 05:49:48 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 15
 by: Oğuz - Sat, 20 Nov 2021 05:49 UTC

On Saturday, November 20, 2021 at 4:20:18 AM UTC+3, Kenny McCormack wrote:
> In myScript line 145:
> [[ "$REPLY" =~ ^\^ ]] && REPLY="title not like '%${REPLY:1}%'"
> ^-- SC1001: This \^ will be a regular '^' in this context.
> ^-- SC2089: Quotes/backslashes will be treated literally. Use an array.
> --- Cut here ---

Looks like a bug in shellcheck.

> The intent is to check to see if $REPLY starts with a ^ and if so, change
> it to the indicated string (yes, I am building up a SQL query). In my
> testing, I determined that the right syntax in a Bash =~ test, to check for
> a leading ^, is ^\^. So, what is the SC1001 complaining about? Isn't that
> the right syntax to use?

It is; the righthand side of `=~' is an ERE and when not inside a bracket expression, an unescaped `^' is an ERE anchoring operator. I'd do `[[ $REPLY = ^* ]]' in this case, though.

Re: shellcheck: What does this mean?

<snajtf$rj09$1@news.xmission.com>

 copy mid

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

 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: shellcheck: What does this mean?
Date: Sat, 20 Nov 2021 10:50:23 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <snajtf$rj09$1@news.xmission.com>
References: <sn9igd$r24n$1@news.xmission.com> <sn9ko9$g1n$1@dont-email.me>
Injection-Date: Sat, 20 Nov 2021 10:50:23 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="904201"; 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 - Sat, 20 Nov 2021 10:50 UTC

In article <sn9ko9$g1n$1@dont-email.me>,
Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
....
>My interpretation is that ^^ is sufficient since there's just one
>single ^ to indicate the start of the line and the second ^ thus
>not interpreted as another start of line but taken literally.
>I read the message just as suggestion to simplify the expression.

In my testing, ^^ didn't work. It matched anything, not just a leading ^.

It is possible I didn't test thoroughly enough, but it seemed that the \
was necessary.

BTW, now that I think about it, I should probably replace this with a case
statement, since I'm actually matching for more than one leading char.
I.e.:

case $REPLY in
^*) ...
%*) ...
....
esac

'case' tends to have fewer surprises than other constructs.

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/Voltaire

Re: shellcheck: What does this mean?

<snb96d$cqp$1@dont-email.me>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: shellcheck: What does this mean?
Date: Sat, 20 Nov 2021 17:53:33 +0100
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <snb96d$cqp$1@dont-email.me>
References: <sn9igd$r24n$1@news.xmission.com> <sn9ko9$g1n$1@dont-email.me>
<snajtf$rj09$1@news.xmission.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 20 Nov 2021 16:53:33 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f84b89f018208ecada9e6d85ac77638e";
logging-data="13145"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18yQIYttP5cvIoMOoOvR2PX"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:AiAZkRilLh/Cv+sfeMkA6rTVEf4=
In-Reply-To: <snajtf$rj09$1@news.xmission.com>
 by: Janis Papanagnou - Sat, 20 Nov 2021 16:53 UTC

On 20.11.2021 11:50, Kenny McCormack wrote:
> In article <sn9ko9$g1n$1@dont-email.me>,
> Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
> ...
>> My interpretation is that ^^ is sufficient since there's just one
>> single ^ to indicate the start of the line and the second ^ thus
>> not interpreted as another start of line but taken literally.
>> I read the message just as suggestion to simplify the expression.
>
> In my testing, ^^ didn't work. It matched anything, not just a leading ^.

You are right, and I cannot explain it, it's strange. - Anyone?

Janis

Re: shellcheck: What does this mean?

<sne5ih$9vb$1@solo.fdn.fr>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!nntp.terraraq.uk!news.gegeweb.eu!gegeweb.org!fdn.fr!.POSTED.meumeu.noiraude.net!not-for-mail
From: lea.g...@noiraude.net (Léa Gris)
Newsgroups: comp.unix.shell
Subject: Re: shellcheck: What does this mean?
Date: Sun, 21 Nov 2021 20:10:08 +0100
Organization: French Data Network
Message-ID: <sne5ih$9vb$1@solo.fdn.fr>
References: <sn9igd$r24n$1@news.xmission.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: base64
Injection-Date: Sun, 21 Nov 2021 19:10:09 -0000 (UTC)
Injection-Info: solo.fdn.fr; posting-host="meumeu.noiraude.net:2001:910:10c6:1::1";
logging-data="10219"; mail-complaints-to="abuse@fdn.fr"
User-Agent: Telnet/1.0 [tlh] (PDP11/DEC)
Content-Language: en-US
In-Reply-To: <sn9igd$r24n$1@news.xmission.com>
 by: Léa Gris - Sun, 21 Nov 2021 19:10 UTC

Le 20/11/2021 à 02:20, Kenny McCormack écrivait :
> --- Cut here ---
> In myScript line 145:
> [[ "$REPLY" =~ ^\^ ]] && REPLY="title not like '%${REPLY:1}%'"
> ^-- SC1001: This \^ will be a regular '^' in this context.
> ^-- SC2089: Quotes/backslashes will be treated literally. Use an array.
> --- Cut here ---
Could not reproduce by checking this line of code with
https://www.shellcheck.net/
Before reporting issue, try to reproduce with shellcheck.net.
The shellcheck version used, might be obsolete and the issue fixed already.
Also, next time don't forget to also show the shell script's the shebang
line and shellcheck version used.
--
Lea

1
server_pubkey.txt

rocksolid light 0.9.7
clearnet tor