[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to detect bash?
From: |
mwoehlke |
Subject: |
Re: How to detect bash? |
Date: |
Tue, 10 Oct 2006 17:12:07 -0500 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.7) Gecko/20060909 Thunderbird/1.5.0.7 Mnenhy/0.7.4.0 |
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" ]
This is probably even more reliable than my first attempt, and also
catches bash running as /bin/sh as 'not bash'. Since I blithely (but
reasonably) assume that /dev/null is the bit-bucket, it's a pretty safe
bet that it can't be executed.
But better to use the hash-bang and make SURE the shell is Bash.
Completely non-workable. That only works if the bash I want is in
/bin/bash. Although I *could* make that correct (I need this to work on
any of a dozen or so computers running about as many OS/hardware
combinations), it defeats the point of my NFS toolchain in which the
bash I want is in /home/install/gnu/<arch>/bin/bash, which can't be put
into a shebang because it isn't constant. And of course would break
things if we were still in bash, but that particular bash wasn't available.
--
Matthew
KDE: Desktop Excellence
- How to detect bash?, mwoehlke, 2006/10/10
- Re: How to detect bash?, Dave Rutherford, 2006/10/10
- Re: How to detect bash?,
mwoehlke <=
- 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