From 7e3a9c23d670347454c6b95e3e6448c9d77fbdc4 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 5 Apr 2024 17:08:57 -0700 Subject: CodingGuidelines: describe "export VAR=VAL" rule https://lore.kernel.org/git/201307081121.22769.tboegi@web.de/ resulted in 9968ffff (test-lint: detect 'export FOO=bar', 2013-07-08) to add a rule to t/check-non-portable-shell.pl script to reject export VAR=VAL and suggest us to instead write it as two statements, i.e., VAR=VAL export VAR This however was not spelled out in the CodingGuidelines document. We may want to re-evaluate the rule since it is from ages ago, but for now, let's make the written rule and what the automation enforces consistent. Signed-off-by: Junio C Hamano --- Documentation/CodingGuidelines | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Documentation/CodingGuidelines') diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index 32e69f798e..96eaeee205 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -188,6 +188,10 @@ For shell scripts specifically (not exhaustive): hopefully nobody starts using "local" before they are reimplemented in C ;-) + - Some versions of shell do not understand "export variable=value", + so we write "variable=value" and then "export variable" on two + separate lines. + - 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. -- cgit v1.3 From be34b51049d1628d1ba4f17e3c087fd01f15f988 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 5 Apr 2024 17:08:58 -0700 Subject: 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 --- Documentation/CodingGuidelines | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'Documentation/CodingGuidelines') diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index 96eaeee205..30bf290418 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. -- cgit v1.3