Re: [PATCH] shell-prompt: clean up nested if-then
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Feb 18, 2013, 23:07 UTC
- Message-ID
- <7vtxp98bmx.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <1361228206.17734.4.camel@mas>
Martin Erik Werner <martinerikwerner@gmail.com> writes:
Show 16 quoted lines
> On Mon, 2013-02-18 at 21:31 +0100, Simon vanaf Telefoon wrote: >> Hi all, sorry for top posting :-( blame the phone and k9 >> >> I have a small issue with the use of test instead of [ >> If that only applies to this section of the entire file. >> Coding style has some value. >> >> Combining nested ifs with && seems harmless enough, though should be >> well tested. >> >> Cheers >> Simon >> > > Ah, indeed, I looked around a bit more, and as per > http://mywiki.wooledge.org/BashPitfalls it seems like 'test' is bad to use with multiple &&'s anyways.
I think you are misreading a suggestion that is somewhat misguided (yes "[ <condition> && <another> ]" does not make sense, but that is not applicable to "test <conditon> && test <another>"); ignore it.
It is fine to write "test <condition> && test <another>" and that works portably to even pre-posix systems.
But the existing code the patch touches favors [] over test consistently; that alone is a good reason to stick with [] in _this_ script, even though it is against Git's overall shell script style.