Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: The best way to know it is in zsh or bash



On Fri, Sep 6, 2019 at 7:42 AM Peng Yu <pengyu.ut@xxxxxxxxx> wrote:
>
> Suppose that I start with bash default login shell, then I call zsh.
>
> I'd like to determine whether I am in bash or zsh.

Where/when is it that you want to do this?  The two shells have an
entirely distinct set of startup files (except that many packaged
distributions have /etc/zshrc loading /etc/bashrc or similar) so I
take it that it's sometime after that?

> I see ZSH_*
> environment variables. Is ZSH_VERSION the most appropriate to be used
> to test whether it is in zsh or not?

The ZSH_* variables are normally global shell parameters, not exported
to the environment.  If something is exporting them, it probably
should not be.

ZSH_VERSION is the oldest of these (if you are worried about
differences within zsh itself), so it should be OK to examine.  See
Mikael's answer.



Messages sorted by: Reverse Date, Date, Thread, Author