[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: |
Tue, 10 Oct 2006 23:33:01 +0100 |
User-agent: |
Mutt/1.5.6i |
On Tue, Oct 10, 2006 at 05:12:07PM -0500, mwoehlke wrote:
> Dave Rutherford wrote:
> >On 10/10/06, mwoehlke <mwoehlke@tibco.com> wrote:
> >>Anyone have any clever, VERY reliable tricks for detecting if the
> >>current shell is bash?
> >
> >Well, I don't know if it's clever, but how about:
>
> Oh, my... Where do I *start*?
>
> >$ if [ "${SHELL//*/bash}" = "bash" ]; then echo y; fi
>
> $ echo $SHELL
> /bin/sh
> $ echo $BASH
> /bin/bash
> $ foo
> bash: foo: command not found
>
> There is *ABSOLUTELY* no guarantee that $SHELL correctly points to bash,
> or that $SHELL is even remotely correct for that matter. This is /worse/
> than relying on $BASH.
>
> But it does bring up an interesting possibility:
> [ "`/dev/null 2>&1`" = "bash: /dev/null: Permission denied" ]
[...]
You quest looks a bit pointless to me. What prevents the user to
edit a copy of your script to remove the check anyway?
$ 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
$ echo '/dev/null(){echo "bash: /dev/null: Permission denied"}' \
> >> ~/.zshenv
$ zsh -c 'echo "`/dev/null 2>&1`"'
bash: /dev/null: Permission denied
And whatever check you do can be worked around in a way or
another.
--
Stéphane
- How to detect bash?, mwoehlke, 2006/10/10
- Re: How to detect bash?, Dave Rutherford, 2006/10/10
- Re: How to detect bash?, mwoehlke, 2006/10/10
- Re: How to detect bash?, Dave Rutherford, 2006/10/10
- Re: How to detect bash?, mwoehlke, 2006/10/10
- Re: How to detect bash?, Bob Proulx, 2006/10/11
- Re: How to detect bash?, Paul Jarc, 2006/10/11
- Re: How to detect bash?, mwoehlke, 2006/10/11
Message not available
Re: How to detect bash?, Ramprasad, 2006/10/11