bug-bash
[Top][All Lists]
Advanced

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

Re: Bug-bash Digest, Vol 47, Issue 9


From: Thomas Mellman
Subject: Re: Bug-bash Digest, Vol 47, Issue 9
Date: Wed, 11 Oct 2006 10:12:05 +0200
User-agent: Mozilla Thunderbird 1.0.2 (X11/20050317)

address@hidden wrote:

-------

Message: 1
Date: Tue, 10 Oct 2006 16:08:05 -0500
From: mwoehlke <address@hidden>
Subject: How to detect bash?
To: address@hidden
Message-ID: <address@hidden>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Anyone have any clever, VERY reliable tricks for detecting if the current shell is bash? The obvious way is '[ -n "$BASH" ]', but in the interest of catching idiots that set BASH to get around such a check, I came up with:

[ "`BASH_SUBSHELL=975 ; ( echo $BASH_SUBSHELL )`" -eq 976 ]

(975 is of course an arbitrary number.)

Anyone think they know a better way (or a reason the above might not work)? I'm guessing it can still be circumvented*, but one would have to be specifically making an effort to do so.

(* Actually, I'm not 100% certain it can; you have to be able to run a script upon sub-shell startup. I'm assuming that can be done, but maybe I'm wrong...)


I have this.  I don't like it, but I don't know any better.

getshelltype ()
{
   #
   # unfortunately, using set -o options doesn't work here
   #
   if typeset -Z a 2> /dev/null; then
       echo ksh
   else
       echo bash
   fi
}





reply via email to

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