Re: [PATCH 2/6] CodingGuidelines: quote assigned value in 'local var=$val'
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Apr 6, 2024, 05:16 UTC
- Message-ID
- <CAPig+cR8HxO5ZeZrJQ4PtpgsqM__cvieZ6g37F1m_=ng6xvSPA@mail.gmail.com>
- In-Reply-To
- <20240406000902.3082301-3-gitster@pobox.com>
On Fri, Apr 5, 2024 at 8:09 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 26 quoted lines
> Dash bug https://bugs.launchpad.net/ubuntu/+source/dash/+bug/139097 > lets the shell erroneously perform field splitting on the expansion > of a command substitution during declaration of a local or an extern > variable. > > The explanation was stolen from ebee5580 (parallel-checkout: avoid > dash local bug in tests, 2021-06-06). > > Signed-off-by: Junio C Hamano <gitster@pobox.com> > --- > diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines > @@ -194,6 +194,20 @@ For shell scripts specifically (not exhaustive): > + - Some versions of dash have broken variable assignment when prefixed > + with "local", "export", and "readonly", in that the value to be > + assigned goes through field splitting at $IFS unless quoted. > + > + DO NOT write: > + > + local variable=$value ;# wrong > + local variable=$(command args) ;# wrong > + > + and instead write: > + > + local variable="$value" > + local variable="$(command args)" > +
Every other example in the shell-script section of this document is written like this:
(incorrect)
local variable=$value
local variable=$(command args) (correct)
local variable="$value"
local variable="$(command args)"Should this patch follow suit for consistency?