Skip to content

Commit be34b51

Browse files
committed
CodingGuidelines: quote assigned value in 'local var=$val'
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 ebee558 (parallel-checkout: avoid dash local bug in tests, 2021-06-06). Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7e3a9c2 commit be34b51

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Documentation/CodingGuidelines

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,18 @@ For shell scripts specifically (not exhaustive):
192192
so we write "variable=value" and then "export variable" on two
193193
separate lines.
194194

195+
- Some versions of dash have broken variable assignment when prefixed
196+
with "local", "export", and "readonly", in that the value to be
197+
assigned goes through field splitting at $IFS unless quoted.
198+
199+
(incorrect)
200+
local variable=$value
201+
local variable=$(command args)
202+
203+
(correct)
204+
local variable="$value"
205+
local variable="$(command args)"
206+
195207
- Use octal escape sequences (e.g. "\302\242"), not hexadecimal (e.g.
196208
"\xc2\xa2") in printf format strings, since hexadecimal escape
197209
sequences are not portable.

0 commit comments

Comments
 (0)