Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

It is much easier to suggest solutions when you know nothing about the problem.


devel / comp.unix.shell / Re: Error msg from shellcheck

SubjectAuthor
* Error msg from shellcheckKenny McCormack
+* Error msg from shellcheckRichard Kettlewell
|`* Error msg from shellcheckKenny McCormack
| `* Error msg from shellcheckRichard Kettlewell
|  `- Error msg from shellcheckKenny McCormack
+* Error msg from shellcheckGeoff Clare
|`* Error msg from shellcheckKenny McCormack
| +- Error msg from shellcheckJanis Papanagnou
| +- Error msg from shellcheckWilliam Ahern
| `- Error msg from shellcheckKaz Kylheku
`- Error msg from shellcheckBen Bacarisse

1
Error msg from shellcheck

<u7h50v$1if2m$1@news.xmission.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6404&group=comp.unix.shell#6404

  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: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Error msg from shellcheck
Date: Wed, 28 Jun 2023 11:19:59 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <u7h50v$1if2m$1@news.xmission.com>
Injection-Date: Wed, 28 Jun 2023 11:19:59 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="1653846"; 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 - Wed, 28 Jun 2023 11:19 UTC

I ran shellcheck on one of my bash scripts and got the output shown below:

*) printf "\a"
^-- SC1117: Backslash is literal in "\a". Prefer explicit escaping: "\\a".
This happens for every instance like this - where I have something like \a
or \n or \r or whatever in a string for things like echo or printf.

This surprises me, b/c the above is perfectly standard and normal. And
works perfectly well, so there clearly is nothing to change or fix here.

In fact, I'd expect something like:

printf "\\a"

to print a literal backslash followed by a literal a. This doesn't happen,
which also surprises ms.

Can someone explain what is going on here and why shellcheck complains?
(Yes, I know shellcheck complains about lots of stuff - most of it bogus -
but this one I find curious...)

--
The key difference between faith and science is that in science, evidence that
doesn't fit the theory tends to weaken the theory (that is, make it less likely to
be believed), whereas in faith, contrary evidence just makes faith stronger (on
the assumption that Satan is testing you - trying to make you abandon your faith).

Re: Error msg from shellcheck

<wwvedlvojpi.fsf@LkoBDZeT.terraraq.uk>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6405&group=comp.unix.shell#6405

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!news.nntp4.net!nntp.terraraq.uk!.POSTED.tunnel.sfere.anjou.terraraq.org.uk!not-for-mail
From: invalid@invalid.invalid (Richard Kettlewell)
Newsgroups: comp.unix.shell
Subject: Re: Error msg from shellcheck
Date: Wed, 28 Jun 2023 13:27:37 +0100
Organization: terraraq NNTP server
Message-ID: <wwvedlvojpi.fsf@LkoBDZeT.terraraq.uk>
References: <u7h50v$1if2m$1@news.xmission.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: innmantic.terraraq.uk; posting-host="tunnel.sfere.anjou.terraraq.org.uk:172.17.207.6";
logging-data="54632"; mail-complaints-to="usenet@innmantic.terraraq.uk"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:RVX9auGVCaWIKPKGu40aLw6qIs4=
X-Face: h[Hh-7npe<<b4/eW[]sat,I3O`t8A`(ej.H!F4\8|;ih)`7{@:A~/j1}gTt4e7-n*F?.Rl^
F<\{jehn7.KrO{!7=:(@J~]<.[{>v9!1<qZY,{EJxg6?Er4Y7Ng2\Ft>Z&W?r\c.!4DXH5PWpga"ha
+r0NzP?vnz:e/knOY)PI-
X-Boydie: NO
 by: Richard Kettlewell - Wed, 28 Jun 2023 12:27 UTC

gazelle@shell.xmission.com (Kenny McCormack) writes:
> I ran shellcheck on one of my bash scripts and got the output shown below:
>
> *) printf "\a"
> ^-- SC1117: Backslash is literal in "\a". Prefer explicit escaping: "\\a".
> This happens for every instance like this - where I have something like \a
> or \n or \r or whatever in a string for things like echo or printf.
>
> This surprises me, b/c the above is perfectly standard and normal. And
> works perfectly well, so there clearly is nothing to change or fix here.

In shell, the string literal "\a" means the two character string 0x5C
0x61, i.e. a backslash followed by lower-case ‘a’.

$ echo "\a" | hd
00000000 5c 61 0a |\a.|
00000003

I guess you expected it to mean 0x07? If so then the mismatch between
expectation and reality seems like justification for the shellcheck
warning.

> In fact, I'd expect something like:
>
> printf "\\a"
>
> to print a literal backslash followed by a literal a. This doesn't happen,
> which also surprises ms.

I don’t know if I’d have predicted it “cold”, but it’s consistent with
the documentation for printf(1).

--
https://www.greenend.org.uk/rjk/

Re: Error msg from shellcheck

<84mtmj-89r.ln1@ID-313840.user.individual.net>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6406&group=comp.unix.shell#6406

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!lilly.ping.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: geoff@clare.See-My-Signature.invalid (Geoff Clare)
Newsgroups: comp.unix.shell
Subject: Re: Error msg from shellcheck
Date: Wed, 28 Jun 2023 13:36:56 +0100
Lines: 43
Message-ID: <84mtmj-89r.ln1@ID-313840.user.individual.net>
References: <u7h50v$1if2m$1@news.xmission.com>
Reply-To: netnews@gclare.org.uk
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net rPYt6LmtYEqP2QzIJQhTrgo7Q7IKnD9ejuXJMJmbUOcx0ct2mE
X-Orig-Path: ID-313840.user.individual.net!not-for-mail
Cancel-Lock: sha1:3V0BR2e+T1fwHbTYjBRW0eipYQc=
User-Agent: Pan/0.145 (Duplicitous mercenary valetism; d7e168a
git.gnome.org/pan2)
 by: Geoff Clare - Wed, 28 Jun 2023 12:36 UTC

Kenny McCormack wrote:

> I ran shellcheck on one of my bash scripts and got the output shown below:
>
> *) printf "\a"
> ^-- SC1117: Backslash is literal in "\a". Prefer explicit escaping: "\\a".
> This happens for every instance like this - where I have something like \a
> or \n or \r or whatever in a string for things like echo or printf.
>
> This surprises me, b/c the above is perfectly standard and normal. And
> works perfectly well, so there clearly is nothing to change or fix here.
>
> In fact, I'd expect something like:
>
> printf "\\a"
>
> to print a literal backslash followed by a literal a. This doesn't happen,
> which also surprises ms.
>
> Can someone explain what is going on here and why shellcheck complains?
> (Yes, I know shellcheck complains about lots of stuff - most of it bogus -
> but this one I find curious...)

According to POSIX, a backslash inside double-quotes escapes the following:

$ ` " \ <newline>

If it isn't followed by one of those, it is treated as a literal backslash.

So in:

printf "\\a"

the first \ escapes the second and printf is passed \a

whereas in:

printf "\a"

the \ is treated as literal and printf is passed \a

--
Geoff Clare <netnews@gclare.org.uk>

Re: Error msg from shellcheck

<u7hal0$1igtq$1@news.xmission.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6407&group=comp.unix.shell#6407

  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: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: Error msg from shellcheck
Date: Wed, 28 Jun 2023 12:56:00 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <u7hal0$1igtq$1@news.xmission.com>
References: <u7h50v$1if2m$1@news.xmission.com> <84mtmj-89r.ln1@ID-313840.user.individual.net>
Injection-Date: Wed, 28 Jun 2023 12:56:00 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="1655738"; 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 - Wed, 28 Jun 2023 12:56 UTC

In article <84mtmj-89r.ln1@ID-313840.user.individual.net>,
Geoff Clare <netnews@gclare.org.uk> wrote:
....
>According to POSIX, a backslash inside double-quotes escapes the following:
>
> $ ` " \ <newline>
>
>If it isn't followed by one of those, it is treated as a literal backslash.
>
>So in:
>
> printf "\\a"
>
>the first \ escapes the second and printf is passed \a
>
>whereas in:
>
> printf "\a"
>
>the \ is treated as literal and printf is passed \a

Exactly. So, you're saying that the two are exactly equivalent - the
underlying command (printf in this case) sees the exact same thing in both
cases.

So, the question is: Why does shellcheck complain?
That's the point of my starting this thread.

(Yes, I know that shellcheck can complain about anything it wants to and
that it often complains about things that are perfectly OK. But I wanted
to start a discussion about shellcheck itself - which is/would be on-topic
in this newsgroup, since it (shellcheck) is often recommended here. In a
way, my overall point is: Don't take shellcheck too seriously...)

--
Kenny, I'll ask you to stop using quotes of mine as taglines.

- Rick C Hodgin -

Re: Error msg from shellcheck

<u7havs$1igtq$2@news.xmission.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6408&group=comp.unix.shell#6408

  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: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: Error msg from shellcheck
Date: Wed, 28 Jun 2023 13:01:48 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <u7havs$1igtq$2@news.xmission.com>
References: <u7h50v$1if2m$1@news.xmission.com> <wwvedlvojpi.fsf@LkoBDZeT.terraraq.uk>
Injection-Date: Wed, 28 Jun 2023 13:01:48 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="1655738"; 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 - Wed, 28 Jun 2023 13:01 UTC

In article <wwvedlvojpi.fsf@LkoBDZeT.terraraq.uk>,
Richard Kettlewell <invalid@invalid.invalid> wrote:
....
>In shell, the string literal "\a" means the two character string 0x5C
>0x61, i.e. a backslash followed by lower-case a.
>
> $ echo "\a" | hd
> 00000000 5c 61 0a |\a.|
> 00000003
>
>I guess you expected it to mean 0x07? If so then the mismatch between
>expectation and reality seems like justification for the shellcheck
>warning.

No, quite the opposite - in terms of what *I* expect. I know shell syntax
as well as (just about) anyone here, and I'm fully aware that the shell
doesn't translate/interpret backslash sequences (unless you ask nicely for
it to do so with something like $'\n').

Maybe the author(s) of shellcheck think that *some* users might expect that.

>> In fact, I'd expect something like:
>>
>> printf "\\a"
>>
>> to print a literal backslash followed by a literal a. This doesn't happen,
>> which also surprises ms.
>
>I don't know if I'd have predicted it cold, but it's consistent with
>the documentation for printf(1).

According to Geoff, passing \\a is exactly the same as passing \a.
(So, there's that...)

--
You know politics has really been turned upside down when you have someone in the
government with a last name of Cheney (Liz, Senator from Wyoming) who is the voice of
reason.

Re: Error msg from shellcheck

<u7hc0o$1pb4f$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6409&group=comp.unix.shell#6409

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Error msg from shellcheck
Date: Wed, 28 Jun 2023 15:19:20 +0200
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <u7hc0o$1pb4f$1@dont-email.me>
References: <u7h50v$1if2m$1@news.xmission.com>
<84mtmj-89r.ln1@ID-313840.user.individual.net>
<u7hal0$1igtq$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 28 Jun 2023 13:19:20 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="459f4a82633cb7bb69ed92876a76c4cc";
logging-data="1879183"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18O7E51Nv2xzPWHSnAyBHDK"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:V0PgmOxL3zzT2fVBVX11iJ04ur0=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <u7hal0$1igtq$1@news.xmission.com>
 by: Janis Papanagnou - Wed, 28 Jun 2023 13:19 UTC

On 28.06.2023 14:56, Kenny McCormack wrote:
>
> So, the question is: Why does shellcheck complain?
> That's the point of my starting this thread.

I don't know anything about the "quality" of that tool.
But didn't you answer that question already in your OP...?

>> (Yes, I know shellcheck complains about lots of stuff -
>> most of it bogus - but this one I find curious...)

I mean; the semantics are obviously clear, so if you care
about that 'spellcheck' tool you could send a bug-report.
OTOH, the tool says:
_Prefer_ explicit escaping: "\\a".
which rather sounds like a style suggestion.

Janis

Re: Error msg from shellcheck

<874jmrof14.fsf@bsb.me.uk>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6410&group=comp.unix.shell#6410

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.unix.shell
Subject: Re: Error msg from shellcheck
Date: Wed, 28 Jun 2023 15:08:39 +0100
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <874jmrof14.fsf@bsb.me.uk>
References: <u7h50v$1if2m$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="3834548ec565e15ab448cff3b241db6f";
logging-data="1890957"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19C2spOkE25CmI1YMkV2R92FqGXBPNchig="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:ML/dlc3hjaHmdQ7G/GyYdzsHecc=
sha1:gaOQ23/hj+bUm8n8wPZHrSxEHGI=
X-BSB-Auth: 1.f018f73223e7c7308907.20230628150839BST.874jmrof14.fsf@bsb.me.uk
 by: Ben Bacarisse - Wed, 28 Jun 2023 14:08 UTC

gazelle@shell.xmission.com (Kenny McCormack) writes:

> I ran shellcheck on one of my bash scripts and got the output shown below:
>
> *) printf "\a"
> ^-- SC1117: Backslash is literal in "\a". Prefer explicit escaping: "\\a".
> This happens for every instance like this - where I have something like \a
> or \n or \r or whatever in a string for things like echo or printf.
>
> This surprises me, b/c the above is perfectly standard and normal. And
> works perfectly well, so there clearly is nothing to change or fix here.
>
> In fact, I'd expect something like:
>
> printf "\\a"
>
> to print a literal backslash followed by a literal a. This doesn't happen,
> which also surprises ms.

This has now been explained.

> Can someone explain what is going on here and why shellcheck
> complains?

Note that it's only saying "prefer". As you are now aware, there's
nothing wrong with "\a" and it means the same as "\\n" but I imagine
that shellcheck is suggesting being explicit. You were a bit surprised
that "\\a" has the same effect, but it had you been in the habit of
explcitily quoting all backslashes I don't think you would have been.
It makes it absolutely clear that printf gets a backslash and an 'a' and
that it is printf the decides what to do with that sequence.

There's also the (tiny) possibility that a new shell might choose to
give "\a" a meaning thereby altering existing script where a change to
the meaning of "\\a" would be unimaginable.

TL;TD: keep everything as unambiguous as possible.

--
Ben.

Re: Error msg from shellcheck

<wwv8rc3oakt.fsf@LkoBDZeT.terraraq.uk>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6411&group=comp.unix.shell#6411

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!news.chmurka.net!nntp.terraraq.uk!.POSTED.tunnel.sfere.anjou.terraraq.org.uk!not-for-mail
From: invalid@invalid.invalid (Richard Kettlewell)
Newsgroups: comp.unix.shell
Subject: Re: Error msg from shellcheck
Date: Wed, 28 Jun 2023 16:44:50 +0100
Organization: terraraq NNTP server
Message-ID: <wwv8rc3oakt.fsf@LkoBDZeT.terraraq.uk>
References: <u7h50v$1if2m$1@news.xmission.com>
<wwvedlvojpi.fsf@LkoBDZeT.terraraq.uk>
<u7havs$1igtq$2@news.xmission.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: innmantic.terraraq.uk; posting-host="tunnel.sfere.anjou.terraraq.org.uk:172.17.207.6";
logging-data="57504"; mail-complaints-to="usenet@innmantic.terraraq.uk"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:QNRl3aKXhuTkp4IuypWsVHbdmag=
X-Face: h[Hh-7npe<<b4/eW[]sat,I3O`t8A`(ej.H!F4\8|;ih)`7{@:A~/j1}gTt4e7-n*F?.Rl^
F<\{jehn7.KrO{!7=:(@J~]<.[{>v9!1<qZY,{EJxg6?Er4Y7Ng2\Ft>Z&W?r\c.!4DXH5PWpga"ha
+r0NzP?vnz:e/knOY)PI-
X-Boydie: NO
 by: Richard Kettlewell - Wed, 28 Jun 2023 15:44 UTC

gazelle@shell.xmission.com (Kenny McCormack) writes:
> Richard Kettlewell <invalid@invalid.invalid> wrote:
> ...
>>In shell, the string literal "\a" means the two character string 0x5C
>>0x61, i.e. a backslash followed by lower-case a.
>>
>> $ echo "\a" | hd
>> 00000000 5c 61 0a |\a.|
>> 00000003
>>
>>I guess you expected it to mean 0x07? If so then the mismatch between
>>expectation and reality seems like justification for the shellcheck
>>warning.
>
> No, quite the opposite - in terms of what *I* expect. I know shell syntax
> as well as (just about) anyone here, and I'm fully aware that the shell
> doesn't translate/interpret backslash sequences (unless you ask nicely for
> it to do so with something like $'\n').

The original post was consistent both with you knowing exactly what was
going on, but also with having two misapprehensions that cancelled each
other out. Since you said you mis-predicted the behavior of the second
printf command, the seccond interpretation is the one I arrived at.

> Maybe the author(s) of shellcheck think that *some* users might expect that.

It’s a reasonable thing to think. For instance anyone more familiar with
C than shell would expect it.

--
https://www.greenend.org.uk/rjk/

Re: Error msg from shellcheck

<u7hrci$1ioj9$1@news.xmission.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6412&group=comp.unix.shell#6412

  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: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: Error msg from shellcheck
Date: Wed, 28 Jun 2023 17:41:38 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <u7hrci$1ioj9$1@news.xmission.com>
References: <u7h50v$1if2m$1@news.xmission.com> <wwvedlvojpi.fsf@LkoBDZeT.terraraq.uk> <u7havs$1igtq$2@news.xmission.com> <wwv8rc3oakt.fsf@LkoBDZeT.terraraq.uk>
Injection-Date: Wed, 28 Jun 2023 17:41:38 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="1663593"; 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 - Wed, 28 Jun 2023 17:41 UTC

In article <wwv8rc3oakt.fsf@LkoBDZeT.terraraq.uk>,
Richard Kettlewell <invalid@invalid.invalid> wrote:
....
>Its a reasonable thing to think. For instance anyone more familiar with
>C than shell would expect it.

Well, as I've tried to make clear, it (this thread) is not about me.

It's about shellcheck - and why they made it work the way they did.

And about whether it is a good thing to recommend to the newbies...

--
There are many self-professed Christians who seem to think that because
they believe in Jesus' sacrifice they can reject Jesus' teachings about
how we should treat others. In this country, they show that they reject
Jesus' teachings by voting for Republicans.

Re: Error msg from shellcheck

<99g1nj-f92.ln1@wilbur.25thandClement.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6413&group=comp.unix.shell#6413

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border-2.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Thu, 29 Jun 2023 23:30:03 +0000
Message-ID: <99g1nj-f92.ln1@wilbur.25thandClement.com>
From: william@25thandClement.com (William Ahern)
Subject: Re: Error msg from shellcheck
Newsgroups: comp.unix.shell
References: <u7h50v$1if2m$1@news.xmission.com> <84mtmj-89r.ln1@ID-313840.user.individual.net> <u7hal0$1igtq$1@news.xmission.com>
User-Agent: tin/2.4.4-20191224 ("Millburn") (OpenBSD/7.3 (amd64))
Date: Thu, 29 Jun 2023 16:21:45 -0700
Lines: 62
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-5BA62rXyA44Y/bSwm+xWOXMOLKgcDRrCovVTlO2fft+YLOpuqlLp/929xvWDqP0Sc5imYotJyHRZjRq!KpZHTyoREmrQCViKAWCU+2EVVOvf06rmwWETjiruEYMEqUFVhcdAlkzhm/7Bga5Z5g==
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
 by: William Ahern - Thu, 29 Jun 2023 23:21 UTC

Kenny McCormack <gazelle@shell.xmission.com> wrote:
> In article <84mtmj-89r.ln1@ID-313840.user.individual.net>,
> Geoff Clare <netnews@gclare.org.uk> wrote:
> ...
>>According to POSIX, a backslash inside double-quotes escapes the following:
>>
>> $ ` " \ <newline>
>>
>>If it isn't followed by one of those, it is treated as a literal backslash.
>>
>>So in:
>>
>> printf "\\a"
>>
>>the first \ escapes the second and printf is passed \a
>>
>>whereas in:
>>
>> printf "\a"
>>
>>the \ is treated as literal and printf is passed \a
>
> Exactly. So, you're saying that the two are exactly equivalent - the
> underlying command (printf in this case) sees the exact same thing in both
> cases.
>
> So, the question is: Why does shellcheck complain?
> That's the point of my starting this thread.

In some other environments where backslash or backslash-style (e.g. %)
escaping is used, including in other shell contexts, an undefined escape
sequence results in a) an error, b) the sequence elided in its entirety, or
c) the sequence treated as an equivalent long form for the ordinary
character. Or even some combination, whether deliberate or accidental,
especially when you consider trailing or truncated sequences (e.g. lone
backslash at the end of a string). For the printf utility, undefined
backslash sequences produce unspecified behavior; for \y Bash produces '\y'
whereas OpenBSD sh produces a diagnostic and 'y'.

Notably, POSIX shell specifies option 'c' for sequences outside quotes,

2.2.1 Escape Character (Backslash)
A <backslash> that is not quoted shall preserve the literal value of the
following character, with the exception of a <newline>.

which is nearly the opposite of the behavior within double-quotes.

Less notable, but you also get option 'c' behavior within bracket
expressions of regular expressions and shell pattern matching notation. IME,
across various environments option 'c' seems the most common, perhaps
because it's closest to DWIM--don't treat the subsequent character as
special, regardless of whether it would otherwise have been treated
differently. For example, in JSON an undefined sequence is illegal, but in
practice most libraries implement option 'c', perhaps because that's what
ECMAScript explicitly specifies[1] for string literals; and Perl both
in strings and regular expressions: "y" =~ /^\y$/ && "\y" =~ /^y$/ or die.

Given the varying treatment of strings in the shell is something of an
enigma to most programmers, arguably even most who regularly write shell
code, that shellcheck diagnostic seems easier to defend than most.

[1] https://262.ecma-international.org/14.0/#prod-CharacterEscapeSequence

Re: Error msg from shellcheck

<20230629173029.370@kylheku.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6414&group=comp.unix.shell#6414

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Error msg from shellcheck
Date: Fri, 30 Jun 2023 00:36:39 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 55
Message-ID: <20230629173029.370@kylheku.com>
References: <u7h50v$1if2m$1@news.xmission.com>
<84mtmj-89r.ln1@ID-313840.user.individual.net>
<u7hal0$1igtq$1@news.xmission.com>
Injection-Date: Fri, 30 Jun 2023 00:36:39 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="087b32d254dbc91709fcb68483fe8244";
logging-data="2422815"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18q/R8C1dCm1qHeykCvzvC5pRjPnp6OSfo="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:T86YiOVk/s8XZ4qAgppynVsDdnE=
 by: Kaz Kylheku - Fri, 30 Jun 2023 00:36 UTC

On 2023-06-28, Kenny McCormack <gazelle@shell.xmission.com> wrote:
> In article <84mtmj-89r.ln1@ID-313840.user.individual.net>,
> Geoff Clare <netnews@gclare.org.uk> wrote:
> ...
>>According to POSIX, a backslash inside double-quotes escapes the following:
>>
>> $ ` " \ <newline>
>>
>>If it isn't followed by one of those, it is treated as a literal backslash.
>>
>>So in:
>>
>> printf "\\a"
>>
>>the first \ escapes the second and printf is passed \a
>>
>>whereas in:
>>
>> printf "\a"
>>
>>the \ is treated as literal and printf is passed \a
>
> Exactly. So, you're saying that the two are exactly equivalent - the
> underlying command (printf in this case) sees the exact same thing in both
> cases.
>
> So, the question is: Why does shellcheck complain?

It's a useless nuisance diagnostic which encourages an undesirable
coding practice. POSIX clearly states, that inside double quotes:

The <backslash> shall retain its special meaning as an escape character
(see Escape Character (Backslash)) only when followed by one of the
following characters when considered special:

$ ` " \ <newline>

Inside double quotes, \a means \a and that's it. Users of printf
depend on this and do not write \\a, which is unidiomatic, and
breaks the deliberate similarity to the C printf.

It should not be diagnosed. Instead, the reverse should be diagnosed!
Whenever a double backslash appears where the second backslash is not
immediately followed by one of the above five characters, shellcheck
should warn about a useless use of backslash escape.

This is not a UUOBE: "\\$". It encodes the text \$.

This is a UUOBE: "\\a", equivalent to "\a".

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor