Re: [PATCH 01/12] tests: add initial bash completion tests
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Apr 8, 2012, 05:41 UTC
- Message-ID
- <7v62daye43.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <20120408044825.GA4296@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 17 quoted lines
> On Sat, Apr 07, 2012 at 09:25:29PM -0700, Junio C Hamano wrote:
>
>> Bash has a special case code to behave in a "posixly correct" mode, where
>> a lot of extensions are disabled, when invoked as "sh". Unfortunately, it
>> still defines BASH_* variables, including BASH, when operating in this
>> mode.
>> [...]
>> So we may want to be a bit more careful like this:
>>
>> if test "z${BASH%/bash}" != "z${BASH}"
>> then
>> : ends with bash so we are already running bash as bash
>
> If bash is in posix mode (including "bash --posix" and being invoked as
> "bin/sh"), it will set POSIXLY_CORRECT (but not export it). Similarly,
> if POSIXLY_CORRECT is set in the outer environment, it will act more
> like sh. So maybe that would be a better test.Yes, but the check needs to be careful to make sure the shell that is running the check is indeed bash, so that it will explicitly exec bash for somebody who is running dash but exports POSIXLY_CORRECT to make GNU programs (other than bash) behave more standard compliant way.
In other words,
if test -n "$POSIXLY_CORRECT" && test -n "$BASH"
then
: we are running bash under posix mode
elif ...or somesuch.