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

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



2019-09-06 09:41:22 -0500, Peng Yu:
> 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. I see ZSH_*
> environment variables. Is ZSH_VERSION the most appropriate to be used
> to test whether it is in zsh or not? Thanks.
> 
> $ declare -p BASH_VERSION
> declare -- BASH_VERSION="5.0.0(1)-release"
> $ declare -p ZSH_VERSION
> typeset ZSH_VERSION=5.6.2
[...]

Just run ps or maybe ps -H (HP/UX, procps):

~$ ps -H
  PID TTY          TIME CMD
32057 pts/13   00:00:00 zsh
32123 pts/13   00:00:00   ps
~$ bash
bash-4.4$ ps -H
  PID TTY          TIME CMD
32057 pts/13   00:00:00 zsh
32124 pts/13   00:00:00   bash
32125 pts/13   00:00:00     ps

ps -o comm= -p "$$"

Will show you the name of the process of id $$ (the pid that executed the
shell).

-- 
Stephane



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