Re: Shell script cleanups/style changes?

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: Shell script cleanups/style changes?

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:43:25

David Kastrup [off-list ref] writes:
Hi, I wanted to ask what the general stance towards shell script
cleanups and simplifications would be.  For example, I find the expr
usage quite inscrutable in commit, and there is no necessity of
putting "shift" in every case branch instead of once behind it, and a
lot of conditionals and other manipulations can be made much easier on
the eye by using parameter expansion patterns that are, as far as I
can see, available with every reasonable Bourne Shell and clones.
The shift in parameter parsing case arms were originally
generated by an automated tool.  If it bothers you, feel free to
move them at the end, I would not mind.  In fact, handcrafted
parameter parser in other scripts do use shift-at-the-end.

As to Bourne-ness of the shell script, please realize that your
maintainer is very old fashioned ;-), but is willing to be
taught new tricks within reason.

We try to limit ourselves to -, =, ?, + (and their colon "if
empty" variants when it really make sense) in parameter
expansion of shell variables.  We also use % and # (and their
"match largest" variants).

Non POSIX substitions such as ${parameter/pattern/string} and
${parameter:offset} are not to be used.  We do not want to
depend on bash.

We try to avoid [ ] and instead spell "test" explicitly; this is
just a personal taste, and not about portability but more about
readability.

After 1.5.3 git-commit.sh will hopefully become built-in, so I
would rather not touch the script.  Certainly, the kind of
change that is "intended to be style-only but somebody needs to
make sure it does not introduce regression to everybody's shell"
is very unwelcome at this point.

Re: Shell script cleanups/style changes?

From: Nguyen Thai Ngoc Duy <hidden>
Date: 2016-06-15 22:43:25

On 8/2/07, Junio C Hamano [off-list ref] wrote:
Non POSIX substitions such as ${parameter/pattern/string} and
${parameter:offset} are not to be used.  We do not want to
depend on bash.
There is in a test (t5300-pack-objects.sh) but I guess the
restrictions do not apply on tests.
-- 
Duy
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help