lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] [PATCH] Fix shellcheck 0.7.2 errors in the CI builds


From: Greg Chicares
Subject: Re: [lmi] [PATCH] Fix shellcheck 0.7.2 errors in the CI builds
Date: Sat, 21 Aug 2021 09:39:02 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0

On 2021-08-19 12:57, Vadim Zeitlin wrote:
> On Thu, 19 Aug 2021 11:13:09 +0000 Greg Chicares <gchicares@sbcglobal.net> 
> wrote:
> 
> GC> On 2021-08-19 02:01, Greg Chicares wrote:
[...]
> GC> > The solution I've been using is to pretend that zsh is sh, and
> GC> > disable each warning specifically. Now that dash is directly
> GC> > supported, I should pretend that zsh is dash instead.
> GC> 
> GC> Belay that. Pretending that zsh is dash just gives one omnibus
> GC> warning like SC2039 (with the up-to-the-minute shellcheck.net).
> GC> It is better to have the specific warnings that shellcheck gives
> GC> when we pretend that zsh is sh.
> 
>  I'm not sure if I really agree with the logic here, why is it better to
> pretend that zsh doesn't support (many) features that it does support and
> disable the warnings about them, rather than avoid the warnings in the
> first place?

When I write shell scripts, I strive to use POSIX sh only, for portability.
If there's a strong reason to use a non-POSIX feature, I use a zsh shebang
and add directives to disable shellcheck's warnings, so I have a complete
list of the deviations from POSIX sh. Someday I might want to rethink those
deviations, so, to me, those shellcheck directives are information, not noise.

> zsh should be 99% upwards-compatible with ksh (and probably
> with dash too, although I'm less sure about this), so IMO it makes much
> more sense to handle zsh scripts as {da,k}sh than just plain sh.

If my goal were simply to encounter fewer warnings for zsh scripts, then
  shellcheck --shell=ksh my_script.zsh
would probably make sense. But that would make it too easy to slide down
the slippery slope of unwitting deviation from POSIX sh orthodoxy. And, for
shellcheck purposes, 99% isn't good enough.

I could strive instead to write only zsh scripts, and rely on zsh's
availability everywhere to ensure portability. That might be just as good,
except that I would lose the benefit of shellcheck.

Or I could abandon zsh in favor of bash or ksh, which are supported by
shellcheck; but I have no wish to learn a different shell.

>  But, while we're on the topic of shellcheck, I'm more interested in
> another question: why do we use the sed hack instead of using shellcheck
> --shell=sh option?

Because I didn't know about it. Fixed now, even if not pushed yet. Thanks.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]