[Top][All Lists]

[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: Gecko/20060909 Thunderbird/ Mnenhy/

Dave Rutherford wrote:
On 10/10/06, mwoehlke <address@hidden> 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
$ echo $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.

KDE: Desktop Excellence

reply via email to

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