git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stefano Lattarini <stefano.lattarini@gmail.com>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: Jon Seymour <jon.seymour@gmail.com>,
	git@vger.kernel.org, gitster@pobox.com, chriscool@tuxfamily.org,
	j6t@kdbg.org, jnareb@gmail.com
Subject: Re: test z$foo = zbar (and Re: [PATCH 1/3] bisect: relax requirement for a working tree.)
Date: Sun, 7 Aug 2011 15:04:59 +0200	[thread overview]
Message-ID: <201108071505.00762.stefano.lattarini@gmail.com> (raw)
In-Reply-To: <20110807124150.GA20046@elie.gateway.2wire.net>

On Sunday 07 August 2011, Jonathan Nieder wrote:
> 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

  parent reply	other threads:[~2011-08-07 13:05 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-07 10:50 [PATCH 0/3] bisect: add support for bisecting bare repositories Jon Seymour
2011-08-07 10:50 ` [PATCH 1/3] bisect: relax requirement for a working tree Jon Seymour
2011-08-07 12:41   ` test z$foo = zbar (and Re: [PATCH 1/3] bisect: relax requirement for a working tree.) Jonathan Nieder
2011-08-07 12:51     ` Jon Seymour
2011-08-07 13:04     ` Stefano Lattarini [this message]
2011-08-07 14:10       ` Jonathan Nieder
2011-08-07 14:40   ` [PATCH 1/3] bisect: relax requirement for a working tree Jon Seymour
2011-08-07 10:50 ` [PATCH 2/3] bisect: add tests for bisection on bare repositories Jon Seymour
2011-08-07 13:39   ` Jonathan Nieder
2011-08-07 14:39     ` Jon Seymour
2011-08-07 10:50 ` [PATCH 3/3] bisect: document that --no-checkout is the default for " Jon Seymour
2011-08-07 13:43   ` Jonathan Nieder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201108071505.00762.stefano.lattarini@gmail.com \
    --to=stefano.lattarini@gmail.com \
    --cc=chriscool@tuxfamily.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=jnareb@gmail.com \
    --cc=jon.seymour@gmail.com \
    --cc=jrnieder@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).