bug-gnulib
[Top][All Lists]
Advanced

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

Re: shell variable references - coding style


From: Bruno Haible
Subject: Re: shell variable references - coding style
Date: Tue, 19 Feb 2019 19:02:08 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-141-generic; KDE/5.18.0; x86_64; ; )

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




reply via email to

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