zsh-users
 help / color / mirror / code / Atom feed
* The best way to know it is in zsh or bash
@ 2019-09-06 14:41 Peng Yu
  2019-09-06 15:11 ` René Wilhelm
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Peng Yu @ 2019-09-06 14:41 UTC (permalink / raw)
  To: zsh-users

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

-- 
Regards,
Peng

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: The best way to know it is in zsh or bash
  2019-09-06 14:41 The best way to know it is in zsh or bash Peng Yu
@ 2019-09-06 15:11 ` René Wilhelm
  2019-09-06 15:38   ` Peng Yu
  2019-09-06 15:16 ` Mikael Magnusson
  2019-09-06 17:41 ` Bart Schaefer
  2 siblings, 1 reply; 7+ messages in thread
From: René Wilhelm @ 2019-09-06 15:11 UTC (permalink / raw)
  To: Peng Yu; +Cc: zsh-users

[-- Attachment #1: Type: text/plain, Size: 498 bytes --]

basename $SHELL

On Fri, 6 Sep 2019 at 16:41, Peng Yu <pengyu.ut@gmail.com> 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. 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
>
> --
> Regards,
> Peng
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: The best way to know it is in zsh or bash
  2019-09-06 14:41 The best way to know it is in zsh or bash Peng Yu
  2019-09-06 15:11 ` René Wilhelm
@ 2019-09-06 15:16 ` Mikael Magnusson
  2019-09-06 17:41 ` Bart Schaefer
  2 siblings, 0 replies; 7+ messages in thread
From: Mikael Magnusson @ 2019-09-06 15:16 UTC (permalink / raw)
  To: Peng Yu; +Cc: zsh-users

On 9/6/19, Peng Yu <pengyu.ut@gmail.com> 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. 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

autotools configure does this, so presumably it works fairly universally,
if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :


-- 
Mikael Magnusson

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: The best way to know it is in zsh or bash
  2019-09-06 15:11 ` René Wilhelm
@ 2019-09-06 15:38   ` Peng Yu
  2019-09-06 15:51     ` gi1242+zsh
  0 siblings, 1 reply; 7+ messages in thread
From: Peng Yu @ 2019-09-06 15:38 UTC (permalink / raw)
  To: René Wilhelm; +Cc: zsh-users

> basename $SHELL

This doesn't work.

$ declare -p BASH_VERSION
declare -- BASH_VERSION="5.0.0(1)-release"
$ zsh
$ declare -p SHELL
export SHELL=/usr/local/bin/bash

-- 
Regards,
Peng

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: The best way to know it is in zsh or bash
  2019-09-06 15:38   ` Peng Yu
@ 2019-09-06 15:51     ` gi1242+zsh
  0 siblings, 0 replies; 7+ messages in thread
From: gi1242+zsh @ 2019-09-06 15:51 UTC (permalink / raw)
  To: zsh-users

For me

    echo $0
    
shows bash / zsh / dash as appropriate.

GI

-- 
When I read about the evils of drinking, I gave up reading.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: The best way to know it is in zsh or bash
  2019-09-06 14:41 The best way to know it is in zsh or bash Peng Yu
  2019-09-06 15:11 ` René Wilhelm
  2019-09-06 15:16 ` Mikael Magnusson
@ 2019-09-06 17:41 ` Bart Schaefer
  2 siblings, 0 replies; 7+ messages in thread
From: Bart Schaefer @ 2019-09-06 17:41 UTC (permalink / raw)
  To: Peng Yu; +Cc: zsh-users

On Fri, Sep 6, 2019 at 7:42 AM Peng Yu <pengyu.ut@gmail.com> 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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: The best way to know it is in zsh or bash
       [not found] <CABrM6w=5V8VnJcX0SNj0s8+EpyJWFqN7EYTYc51rNpTYQ_p9vw__33715.8397933067$1567780959$gmane$org@mail.gmail.com>
@ 2019-09-06 19:02 ` Stephane Chazelas
  0 siblings, 0 replies; 7+ messages in thread
From: Stephane Chazelas @ 2019-09-06 19:02 UTC (permalink / raw)
  To: Peng Yu; +Cc: zsh-users

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-09-07  0:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-06 14:41 The best way to know it is in zsh or bash Peng Yu
2019-09-06 15:11 ` René Wilhelm
2019-09-06 15:38   ` Peng Yu
2019-09-06 15:51     ` gi1242+zsh
2019-09-06 15:16 ` Mikael Magnusson
2019-09-06 17:41 ` Bart Schaefer
     [not found] <CABrM6w=5V8VnJcX0SNj0s8+EpyJWFqN7EYTYc51rNpTYQ_p9vw__33715.8397933067$1567780959$gmane$org@mail.gmail.com>
2019-09-06 19:02 ` Stephane Chazelas

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).