bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Jim Meyering <jim@meyering.net>
To: Bruno Haible <bruno@clisp.org>
Cc: Pavel Raiskup <praiskup@redhat.com>,
	"bug-gnulib@gnu.org List" <bug-gnulib@gnu.org>
Subject: Re: shell variable references - coding style
Date: Tue, 19 Feb 2019 11:41:27 -0800	[thread overview]
Message-ID: <CA+8g5KHWrhFeM_CdVcdq16FNd9wn2KHQ8JAYd-XjSP0YM3g4TQ@mail.gmail.com> (raw)
In-Reply-To: <2794770.VEEVdL9LWF@omega>

On Tue, Feb 19, 2019 at 10:02 AM Bruno Haible <bruno@clisp.org> wrote:
>
> Hi Pavel,
>
> > > [...]
> > > This patch fixes both issues, and makes the IFS handling a bit more robust.
> > > [...]
> >
> > > -    case $_fpf_arg in
> > > +    case "$_fpf_arg" in
> > > [...]
> > > -  fpf_dirs=$1 ; shift
> > > -  fpf_cb=$1 ; shift
> > > +  fpf_dirs="$1"; shift
> > > +  fpf_cb="$1"; shift
> > > [...]
> >
> > ... and so on, I don't think it is more robust.  At least according to
> > Autoconf's Shellology [1] it should be actually better to write it the
> > other way around (without additional quotes).
>
> I do think it is more robust, because
>   * The number one mistake in shell scripts (measured by frequency of
>     occurrence) is to reference variables without double quotes when word
>     splitting is in fact undesired.
>   * Simple rules are easier to follow by programmers, resulting in fewer bugs.
>   * The rule
>       "Always double-quote shell variable references, except if you DO
>        want word-splitting."
>     is simpler than
>       "Always double-quote shell variable references, except if you DO
>        want word-splitting OR in the right-hand side of assignments OR
>        as argument of 'case' statements."
>
> The text that you quote says two different things:
>   * Backquotes inside double-quotes are hairy.
>     There is a simple rule to avoid them: When you have a backquote
>     expression, always first assign its result to a variable. Then use
>     the variable (with double-quotes, usually).
>   * Bash 4.1 has a bug when you WANT word splitting.
> These two things don't make my style rule
>   "Always double-quote shell variable references, except if you DO
>    want word-splitting."
> less robust.
>
> > FTR, Gary Vaughan has wrote a syntax checker rules for protecting us from
> > adding such statements into libtool codebase.
>
> Opinions regarding coding style differ. Gary is entitled to his opinion, as
> much as I am entitled to mine.
>
> Bruno
>
> > [1] https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/
> > Shell-Substitutions.html

I too prefer to avoid double quotes after assignment-"=": less syntax
feels slightly more maintainable, here.
These days I rely heavily on shellcheck. I find it to be very useful,
and at least by default it doesn't complain about such usage.


  reply	other threads:[~2019-02-19 19:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-14 19:53 gnulib-tool: Improve handling of multiple --local-dir options Bruno Haible
2019-02-19 15:39 ` Pavel Raiskup
2019-02-19 18:02   ` shell variable references - coding style Bruno Haible
2019-02-19 19:41     ` Jim Meyering [this message]
2019-03-13 12:46     ` Pavel Raiskup
2019-03-13 17:15       ` Paul Eggert
2019-03-13 19:04       ` Bruno Haible
2019-02-19 18:18   ` gnulib-tool: Improve handling of multiple --local-dir options Bruno Haible
2019-02-20  7:03     ` Pavel Raiskup

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CA+8g5KHWrhFeM_CdVcdq16FNd9wn2KHQ8JAYd-XjSP0YM3g4TQ@mail.gmail.com \
    --to=jim@meyering.net \
    --cc=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    --cc=praiskup@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).