]> git.ipfire.org Git - thirdparty/git.git/commitdiff
CodingGuidelines: quote assigned value in 'local var=$val'
authorJunio C Hamano <gitster@pobox.com>
Sat, 6 Apr 2024 00:08:58 +0000 (17:08 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sat, 6 Apr 2024 05:50:05 +0000 (22:50 -0700)
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>
Documentation/CodingGuidelines

index 96eaeee2054b1c5d517af26b33905dc97515018c..30bf2904183570bc1899c77e6d6569052122b2fb 100644 (file)
@@ -192,6 +192,18 @@ For shell scripts specifically (not exhaustive):
    so we write "variable=value" and then "export variable" on two
    separate lines.
 
+ - 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.
+
+       (incorrect)
+       local variable=$value
+       local variable=$(command args)
+
+       (correct)
+       local variable="$value"
+       local variable="$(command args)"
+
  - Use octal escape sequences (e.g. "\302\242"), not hexadecimal (e.g.
    "\xc2\xa2") in printf format strings, since hexadecimal escape
    sequences are not portable.