git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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.

Previous: Jonathan NiederNext: Simon Oosthoek
Message 6 of 8 in “shell-prompt: clean up nested if-then”
  1. shell-prompt: clean up nested if-thenMartin Erik Werner, Feb 18, 2013
  2. Jonathan NiederFeb 18, 2013
  3. Martin Erik WernerFeb 18, 2013
  4. shell-prompt: clean up nested if-thenmartinerikwerner@gmail.com, Feb 18, 2013
  5. Jonathan NiederFeb 18, 2013
  6. Junio C HamanoFeb 18, 2013
  7. Simon OosthoekFeb 19, 2013
  8. Junio C HamanoFeb 19, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.