[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: definite way to determine the running shell
From: |
Eduardo A . Bustamante López |
Subject: |
Re: definite way to determine the running shell |
Date: |
Fri, 27 Mar 2015 01:44:30 -0600 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
Why would the user set BASH_VERSION in the environment? That sounds like asking
for trouble!
If you're against someone who actively tries to fool you into thinking you're
in bash, then it'll be very hard.
One way that I think would work is to:
- 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.
This would be one way to make sure you're really in bash, even when someone is
trying to fool you.
Another way would be to create a battery of tests of behavior that's unique to
bash, in stuff that's not specified by POSIX, or that its specification is a
bit ambiguous. One example of this is:
dualbus@yaqui ~ % for sh in bash mksh zsh ksh93 dash; do $sh -c
't=${KSH_VERSION+typeset}; f() { x=3; ${t:-local} x; echo $x; }; [ "$(f)" =
"$(x=4 f)" ]'; echo $sh $?; done
bash 1
mksh 0
zsh 0
ksh93 0
dash 0
That's a case where it'd be hard to fake that you're bash.
--
Eduardo Bustamante https://dualbus.me/
- definite way to determine the running shell, Christoph Anton Mitterer, 2015/03/26
- Re: definite way to determine the running shell,
Eduardo A . Bustamante López <=
- Re: definite way to determine the running shell, Clark Wang, 2015/03/27
- Re: definite way to determine the running shell, Andreas Schwab, 2015/03/27
- Re: definite way to determine the running shell, Eric Blake, 2015/03/27
- Re: definite way to determine the running shell, Christoph Anton Mitterer, 2015/03/27
- Re: definite way to determine the running shell, Greg Wooledge, 2015/03/27
- Re: definite way to determine the running shell, Christoph Anton Mitterer, 2015/03/27
- Re: definite way to determine the running shell, Greg Wooledge, 2015/03/27
- Re: definite way to determine the running shell, Christoph Anton Mitterer, 2015/03/27