Skip to content

Commit bc97994

Browse files
committed
CodingGuidelines: reword parameter expansion section
Group entries related to parameter substitutions together and avoid using the word "regexp" to refer to the ${parameter/pattern/string} substitution (banned), as the pattern there is a shell glob and not a regular expression. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 537497b commit bc97994

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

Documentation/CodingGuidelines

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,28 @@ For shell scripts specifically (not exhaustive):
3535
properly nests. It should have been the way Bourne spelled
3636
it from day one, but unfortunately isn't.
3737

38-
- We use ${parameter-word} and its [-=?+] siblings, and their
39-
colon'ed "unset or null" form.
38+
- We use POSIX compliant parameter substitutions and avoid bashisms;
39+
namely:
4040

41-
- We use ${parameter#word} and its [#%] siblings, and their
42-
doubled "longest matching" form.
41+
- We use ${parameter-word} and its [-=?+] siblings, and their
42+
colon'ed "unset or null" form.
4343

44-
- We use Arithmetic Expansion $(( ... )).
44+
- We use ${parameter#word} and its [#%] siblings, and their
45+
doubled "longest matching" form.
4546

46-
- Inside Arithmetic Expansion, spell shell variables with $ in front
47-
of them, as some shells do not grok $((x)) while accepting $(($x))
48-
just fine (e.g. dash older than 0.5.4).
47+
- No "Substring Expansion" ${parameter:offset:length}.
4948

50-
- No "Substring Expansion" ${parameter:offset:length}.
49+
- No shell arrays.
5150

52-
- No shell arrays.
51+
- No strlen ${#parameter}.
5352

54-
- No strlen ${#parameter}.
53+
- No pattern replacement ${parameter/pattern/string}.
5554

56-
- No regexp ${parameter/pattern/string}.
55+
- We use Arithmetic Expansion $(( ... )).
56+
57+
- Inside Arithmetic Expansion, spell shell variables with $ in front
58+
of them, as some shells do not grok $((x)) while accepting $(($x))
59+
just fine (e.g. dash older than 0.5.4).
5760

5861
- We do not use Process Substitution <(list) or >(list).
5962

0 commit comments

Comments
 (0)