CodingGuidelines: avoid "test <cond> -a/-o <cond>"
The construct is error-prone; "test" being built-in in most modern shells, the reason to avoid "test <cond> && test <cond>" spawning one extra process by using a single "test <cond> -a <cond>" no longer exists. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
May 20, 2014 at 11:12 UTC
897f964c0dce8e7cc2cc53bb19b83cadce106773
1 file changed
+13
Documentation/CodingGuidelines
+13
@@ -151,6 +151,19 @@ For shell scripts specifically (not exhaustive):
151
interface translatable. See "Marking strings for translation" in
152
po/README.
153
154
+ - We do not write our "test" command with "-a" and "-o" and use "&&"
155
+ or "||" to concatenate multiple "test" commands instead, because
156
+ the use of "-a/-o" is often error-prone. E.g.
157
+
158
+ test -n "$x" -a "$a" = "$b"
159
+
160
+ is buggy and breaks when $x is "=", but
161
+
162
+ test -n "$x" && test "$a" = "$b"
163
+
164
+ does not have such a problem.
165
+
166
+
167
For C programs:
168
169
- We use tabs to indent, and interpret tabs as taking up to