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

Re: test z$foo = zbar (and Re: [PATCH 1/3] bisect: relax requirement for a working tree.)

From
Stefano Lattarini <stefano.lattarini@gmail.com>
Date
Aug 7, 2011, 13:04 UTC
Message-ID
<201108071505.00762.stefano.lattarini@gmail.com>
In-Reply-To
<20110807124150.GA20046@elie.gateway.2wire.net>
On Sunday 07 August 2011, Jonathan Nieder wrote:
Show 27 quoted lines
> Am I the only one who finds this
> 
> 	test "z$foo" = "zbar"
> 
> style to be impossibly ugly?  It means every time someone considers
> using the "test" utility, they decide "is this expression likely to
> looks like an operator" and each time someone reads a use of the
> "test" utility, there is a lingering question of whether that choice
> was made correctly.  By contrast, if one follows the following simple
> rules, everything works fine with the shells git supports:
> 
>  - _Do_ use the "z$foo" trick when using expr.
>  - Do not use test's '(', '),' -a and -o operators; use && and ||
>    instead.
> 
> The Autoconf manual says
> 
> 	Posix also says that ‘test ! "string"’, ‘test -n "string"’ and
> 	‘test -z "string"’ work with any string, but many shells (such
> 	as Solaris, AIX 3.2, UNICOS 10.0.0.6, Digital Unix 4, etc.)
> 	get confused if string looks like an operator:
> 
> Notice that none of the mentioned shells is close enough to POSIX even
> to support $( / ).  This is an area in which early POSIX work improved
> shells immensely (the "-e" primary was introduced around the same
> time).
>

While this is true, some problems with the `test' builtin persists also with in more "posixy" shells. For example, with Solaris /bin/ksh and /usr/xpg4/bin/sh (the latter expected to be the default POSIX-compliant shell on the system, since as you've noticed /bin/sh is defintely not compliant there), one sees:

  $ /usr/xpg4/bin/sh -c 'test -z ")"'; echo $?
  0
  $ /bin/ksh -c 'test -z ")"'; echo $?
  0
This will be documented in the next version of the Autoconf manual BTW.
Regards,
  Stefano
Previous: Jon SeymourNext: Jonathan Nieder
Message 5 of 12 in “bisect: add support for bisecting bare repositories”
  1. 0/3 bisect: add support for bisecting bare repositoriesJon Seymour, Aug 7, 2011
  2. 1/3 bisect: relax requirement for a working tree.Jon Seymour, Aug 7, 2011
  3. test z$foo = zbar (and Re: [PATCH 1/3] bisect: relax requirement for a working tree.)Jonathan Nieder, Aug 7, 2011
  4. Jon SeymourAug 7, 2011
  5. Stefano LattariniAug 7, 2011
  6. Jonathan NiederAug 7, 2011
  7. Jon SeymourAug 7, 2011
  8. 2/3 bisect: add tests for bisection on bare repositoriesJon Seymour, Aug 7, 2011
  9. Jonathan NiederAug 7, 2011
  10. Jon SeymourAug 7, 2011
  11. 3/3 bisect: document that --no-checkout is the default for bare repositoriesJon Seymour, Aug 7, 2011
  12. Jonathan NiederAug 7, 2011

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.