Skip to content

Commit 897f964

Browse files
committed
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 <[email protected]>
1 parent f26443d commit 897f964

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Documentation/CodingGuidelines

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,19 @@ For shell scripts specifically (not exhaustive):
151151
interface translatable. See "Marking strings for translation" in
152152
po/README.
153153

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+
154167
For C programs:
155168

156169
- We use tabs to indent, and interpret tabs as taking up to

0 commit comments

Comments
 (0)