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@xxxxxxxxx> --- * The coding guidelines now forbids use of local/export var=$val without having $val quoted inside a pair of double quotes to avoid portability bugs. > Isn't this the same as what ebee5580 (parallel-checkout: avoid dash > local bug in tests, 2021-06-06) fixed? Documentation/CodingGuidelines | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git i/Documentation/CodingGuidelines w/Documentation/CodingGuidelines index 32e69f798e..8aa76094ca 100644 --- i/Documentation/CodingGuidelines +++ w/Documentation/CodingGuidelines @@ -188,6 +188,20 @@ For shell scripts specifically (not exhaustive): hopefully nobody starts using "local" before they are reimplemented in C ;-) + - Some versions of dash has 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 + export variable=$(command args) ;# wrong + + and instead write: + + local variable="$value" + export 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.