[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to detect bash?

From: Stephane Chazelas
Subject: Re: How to detect bash?
Date: Wed, 11 Oct 2006 08:24:19 +0100
User-agent: Mutt/1.5.6i

On Tue, Oct 10, 2006 at 06:14:22PM -0500, mwoehlke wrote:
> >$ zsh -c 'echo "`/dev/null 2>&1`"' bash
> >bash: /dev/null: Permission denied
> >
> >$ zsh
> >$ ARGV0=bash ash -c 'echo "`/dev/null 2>&1`"; echo $BASH'
> >bash: /dev/null: Permission denied
> Eh? I get:
> $ zsh -c 'echo "`/dev/null 2>&1`"' bash
> zsh:1: permission denied: /dev/null

Well, I do get what I said with zsh 4.3.2

> $ ARGV0=bash ash -c 'echo "`/dev/null 2>&1`"; echo $BASH'
> /dev/null: permission denied

(note that this command must be run from zsh which uses
ARGV0=... to set ash's argv[0]).

You must have an older /ash/ than I have mine is one of the
OpenBSD based sh ones (found on debian).

> So neither of your counter-examples is working for me (although both 
> look like they *should*; go figure).

Though I'd bet the third one with .zshenv worked.

> But since you didn't counter 
> BASH_SUBSHELL (and since I'm too lazy to change it now) I guess I'll 
> stick with that. :-)

BASH_SUBSHELL is a relatively recent addition to bash. Most
systems still don't have a bash3.

$ bash -c 'echo "$BASH_VERSION, <$BASH_SUBSHELL>"'
2.05b.0(2)-release, <>

> True, but the main point of the exercise is to go with a check that's 
> unlikely to be worked around "by accident". If someone intentionally 
> circumvents the check (and you're right, editing the script would be 
> easy), well then they deserve whatever happens. But I *am* paranoid 
> enough to not trust that $BASH is never set - other than by bash - for 
> some reason. Or that it hasn't been *unset* (since that seems to kill it 
> forever), because we have 'clean environment' scripts that would do this 
> sort of thing.

Then I'd go with $BASH_VERSION as someone else suggested which
is in every bash version.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]