bug-bash
[Top][All Lists]
Advanced

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

Re: definite way to determine the running shell


From: Dan Douglas
Subject: Re: definite way to determine the running shell
Date: Fri, 27 Mar 2015 14:47:25 -0500

On Fri, Mar 27, 2015 at 2:37 PM, Christoph Anton Mitterer
<address@hidden> wrote:
> On Fri, 2015-03-27 at 01:44 -0600, Eduardo A. Bustamante López wrote:
>> Why would the user set BASH_VERSION in the environment? That sounds like 
>> asking
>> for trouble!
> Murphy's law! :D
>
>> - try to unset BASHOPTS (did it work? then it's not bash)
>> - Now, store the value of BASHOPTS in a temp var
>> - Set a shopt option that's not set already in BASHOPTS (or unset one from
>> BASHOPTS)
>> - Check if the value of BASHOPTS changed.
> that sounds like a nice idea.

This might not be a great idea. Even if it works now it's not
future-proof. Some shells have implemented BASH-prefixed variables for
the sake of compatibility. I understand why they did it and don't
think it was a bad idea, it just means you can't rely on their
presence to mean you're using bash.

ksh93's bash mode and mksh both have examples of this

 $ exec -a bash ksh -c 'typeset -p' | grep BASH
BASH=bash
BASH_EXECUTION_STRING='typeset -p'
typeset -r -a BASH_VERSINFO=(4 2 0 0 ksh93 i386-unknown-linux)
BASH_VERSION='4.2.0(0)-ksh93'
typeset -n BASH_REMATCH='.sh.match[0]'
typeset -n BASH_SOURCE=file
typeset -n BASH_SUBSHELL=subshell

 $ mksh -c 'typeset -p' | grep BASH
typeset -i -U BASHPID=1207

-- 
Dan Douglas



reply via email to

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