diff options
author | Junio C Hamano <gitster@pobox.com> | 2024-04-06 00:08:58 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-04-06 05:50:05 (GMT) |
commit | be34b51049d1628d1ba4f17e3c087fd01f15f988 (patch) | |
tree | 6f70d7df5dfc64073b598f131f30ca4c092acd48 /Documentation | |
parent | 7e3a9c23d670347454c6b95e3e6448c9d77fbdc4 (diff) | |
download | git-be34b51049d1628d1ba4f17e3c087fd01f15f988.zip git-be34b51049d1628d1ba4f17e3c087fd01f15f988.tar.gz git-be34b51049d1628d1ba4f17e3c087fd01f15f988.tar.bz2 |
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 ebee5580 (parallel-checkout: avoid
dash local bug in tests, 2021-06-06).
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'Documentation')
-rw-r--r-- | Documentation/CodingGuidelines | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index 96eaeee..30bf290 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -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. |