From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-3.6 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id AEFBE20248 for ; Wed, 13 Mar 2019 12:54:22 +0000 (UTC) Received: from localhost ([127.0.0.1]:44116 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h43Ok-0001gh-Q4 for normalperson@yhbt.net; Wed, 13 Mar 2019 08:54:18 -0400 Received: from eggs.gnu.org ([209.51.188.92]:36678) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h43Of-0001fD-F2 for bug-gnulib@gnu.org; Wed, 13 Mar 2019 08:54:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h43Oe-0002D1-AW for bug-gnulib@gnu.org; Wed, 13 Mar 2019 08:54:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44748) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h43Od-0002B9-Vl for bug-gnulib@gnu.org; Wed, 13 Mar 2019 08:54:12 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B512D6855F; Wed, 13 Mar 2019 12:46:30 +0000 (UTC) Received: from raiskup.localnet (unknown [10.43.2.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0C4F517D42; Wed, 13 Mar 2019 12:46:29 +0000 (UTC) From: Pavel Raiskup To: bug-gnulib@gnu.org Subject: Re: shell variable references - coding style Date: Wed, 13 Mar 2019 13:46:29 +0100 Message-ID: <17659437.mmpk6nfPDD@raiskup> Organization: Red Hat In-Reply-To: <2794770.VEEVdL9LWF@omega> References: <6157407.BPRi2t5o0z@omega> <33012288.smD7kdOuTz@raiskup> <2794770.VEEVdL9LWF@omega> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 13 Mar 2019 12:46:30 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bruno Haible Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" On Tuesday, February 19, 2019 7:02:08 PM CET Bruno Haible 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. Is there a gnulib/GNU-preferred way to do this, defined somewhere? I'd like to avoid such mistakes in future so the code I add doesn't need an unnecessary rewrites (such style changes only complicate git-log reading, and hide the real gist of the changes). Pavel > Bruno > > > [1] https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/ > > Shell-Substitutions.html > > >