Dave Rutherford wrote:
On 10/10/06, mwoehlke <[EMAIL PROTECTED]> 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



_______________________________________________
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash

Reply via email to