Eric Sunshine [off-list ref] writes:
On Tue, Jun 13, 2023 at 1:44 PM Jonathan Tan [off-list ref] wrote:
quoted
Hexadecimal escapes in shell scripts are not portable across shells (in
particular, "dash" does not support them). Write in the CodingGuidelines
document that we should be using octal escapes instead.
Signed-off-by: Jonathan Tan <redacted>
---
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
@@ -188,6 +188,9 @@ For shell scripts specifically (not exhaustive):
+ - Use octal escape sequences (e.g. "\302\242"), not hexadecimal (e.g.
+ "\xc2\xa2"), as the latter is not portable.
The shell itself doesn't interpret these sequences, so this
description feels too generic. Perhaps it would make more sense to
cite specific tools for which octal sequences are needed for
portability reasons, such as `printf`, `sed`, `tr`, etc.
Ah...good point. I checked with "echo" in "dash" and assumed that it
was "dash" that was interpreting the escapes, but indeed it is the
"echo" (and "printf") builtins in "dash" that are actually interpreting
them. What do you think of the following in the commit message:
Hexadecimal escapes in shell scripts are not portable across shell builtins (in
particular, the "printf" of "dash" does not support them). Write in the CodingGuidelines
document that we should be using octal escapes instead.
and in the CodingGuidelines doc:
+ - Use octal escape sequences (e.g. "\302\242"), not hexadecimal (e.g.
+ "\xc2\xa2"), as the latter is not portable across some shell builtins like printf.