From: Junio C Hamano Date: Tue, 06 Nov 2007 21:06:00 GMT Subject: Re: [PATCH 3/5] Replace $((...)) with expr invocations. Message-ID: <7vtznzf5jb.fsf@gitster.siamese.dyndns.org> In-Reply-To: <20071106202600.GH6361@ins.uni-bonn.de> Ralf Wildenhues writes: > * Ralf Wildenhues wrote on Tue, Nov 06, 2007 at 09:18:09PM CET: >> --- >> git-filter-branch.sh | 4 ++-- >> git-rebase--interactive.sh | 8 ++++---- >> git-rebase.sh | 8 ++++---- >> 3 files changed, 10 insertions(+), 10 deletions(-) > > Hmm, maybe this one is overkill. $((...)) is POSIX, I temporarily > forgot (thanks BenoƮt!). > > I'm unsure whether git targets non-POSIX Bourne shells like Solaris > /bin/sh. That would however mean replacing stuff like $(cmd) with > `cmd` as well, and from grepping the source it looks like you'd rather > avoid that. For git, two rough rules are: - Most importantly, we never say "It's in POSIX; we'll happily screw your system that does not conform." We live in the real world. - However, we often say "Let's stay away from that construct, it's not even in POSIX". For shell scripts specifically (not exhaustive): - We prefer $( ... ) for command substitution; unlike ``, it properly nests. It should have been the way Bourne spelled it from day one, but unfortunately isn't. - We use ${parameter-word} and its [-=?+] siblings, and their colon'ed "unset or null" form. - We use ${parameter#word} and its [#%] siblings, and their doubled "longest matching" form. - We use Arithmetic Expansion $(( ... )). - No "Substring Expansion" ${parameter:offset:length}. - No shell arrays. - No strlen ${#parameter}. - No regexp ${parameter/pattern/string}. - We do not use Process Substitution <(list) or >(list). - We prefer "test" over "[ ... ]". - We do not write noiseword "function" in front of shell functions.