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: Clark Wang
Subject: Re: definite way to determine the running shell
Date: Fri, 27 Mar 2015 12:52:45 +0800

On Fri, Mar 27, 2015 at 11:36 AM, Christoph Anton Mitterer <address@hidden> wrote:
Hey.

There are a lot of articles on the web about detecting the actually
running shell.
Unfortunately, just relying on $SHELL doesn't really work since when I
invoke e.g. csh from bash, it would be still $SHELL=bash and I guess I
won't be able to convince all shell upstreams to overwrite $SHELL (which
IMHO would be much better, and more like $TERM).

Now I see basically two other ways to detect a shell:
a) using ps or something similar... which is not really portable either
and can be rather easily/accidentally fooled

b) Using some env vars typically to the shell, e.g. BASH_VERSION for
bash.
AFAIU per default these are not declared'ed -x , so when I rund fooShell
from bash it wouldn't be inherited.
But the user could still manually mark it exportable.

c) I've also thought about somehow using e.g. shopt, when it runs I
could be sure, it was bash. But for that in turn I'd need to make sure
whether it's a built-in command, which works in bash with the "builtin"
built in command ;) ... but not portably as in POSIX shell command
language (at least not that I'd know).


Is there some better way to do this (at least to detect bash)? E.g. some
VAR that bash sets and that it would neither take from its own
environment when being started nor that it would pass on to processes?

For bash I think you can just check $BASH_VERSION.

Also see Sven Mascheck's whatshell: http://www.in-ulm.de/~mascheck/various/whatshell/ .

-clark

Thanks,
Chris.


reply via email to

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