Which shell I am using in mac
Asked Answered
I

3

93

Default shell in my mac was bash.
I have tried to change it into ZSH by command chsh -s /bin/zsh.

Now when I am trying to check the shell type, I am getting different responses.

COMMAND-1

input : echo $SHELL
output : /bin/zsh

COMMAND-2

input : ps $o
output : 7655 ttys002 0:00.03 -bash

COMMAND-3

input : ps -p $$ | awk '$1 == PP {print $4}' PP=$$
output : -bash

I am not sure which shell I am using. Do I need to do something additional to change my shell into ZSH.

Interlay answered 14/4, 2017 at 18:29 Comment(6)
Did you logout and login after running chsh? Or, at least, restart your terminal.Shivaree
In the General tab of Terminal's preferences, is "Shell opens with" set to "Default login shell?"Relinquish
It's unclear what $o does in your 2nd command - what is the value of $o?Advertisement
Did you put zsh and its path in /etc/shells?Trammell
it was already there.Interlay
how do I additionally make sure that my .zshrc file is being ran? I don't see my aliases working as of right now...Catanzaro
R
26

macOS's Terminal allows you to specify the shell in its preferences. By default, it is set to use your login shell, but it looks like you've overridden it to use Bash.

In the General tab of Terminal's preferences, set it to "Default login shell," to prevent your login shell from being overridden:

Terminal's settings

Also, make sure the "Run command" checkbox is not checked in the Shell tab of your profiles' settings:

Profile settings

Relinquish answered 14/4, 2017 at 18:50 Comment(2)
the general settings - as of right now 2021 december - have changedCatanzaro
@CharlieParker: Terminal preferences wouldn't change based on a date; they might change based on a revision, but not on a date.Fix
A
107

To see what shell is currently running - which may or may not be your default shell - use:

# Prints something like '/bin/ksh' or '-zsh'
# See bottom section if you always need the full path.
ps -o comm= $$

The above assumes that the running shell is a POSIX-compatible shell. If the running shell is PowerShell, replace $$ with $PID, which will tell you the full path even if PowerShell is also the default shell. If you use
(Get-Process -Id $PID).Path instead, you'll get the full path with symlinks resolved, if any.

To see what shell is your default shell, run:

echo $SHELL

If the currently running shell is PowerShell: $env:SHELL


If you need to know the full path of the currently running shell:

If the current shell was launched directly by Terminal.app (or iTerm2), it is a login shell launched via the login utility, which causes the current shell process to self-report its binary abstractly as -<binary-filename>, e.g. -zsh; that is, you don't get the full path of the binary underlying the shell process.

If always obtaining the full path is required - e.g. if you want to distinguish the system Bash /bin/bash from a later version installed via Homebrew - you can use the following command line:

(bin="$(ps -o comm= $$)"; expr "$bin" : '\(-\)' >/dev/null && bin="$(ps -o command= $PPID | grep -Eo ' SHELL=[^ ]+' | cut -f 2- -d =)"; [ -n "$bin" ] && echo "$bin" || echo "$SHELL")
Advertisement answered 14/4, 2017 at 19:9 Comment(2)
how do I additionally make sure that my .zshrc file is being ran? I don't see my aliases working as of right now...Catanzaro
@CharlieParker, if zsh is your default shell, ~/.zshrc should automatically be sourced in interactive sessions. You can place an echo command in there to diagnose. If you need further help, please create a new question post.Advertisement
R
26

macOS's Terminal allows you to specify the shell in its preferences. By default, it is set to use your login shell, but it looks like you've overridden it to use Bash.

In the General tab of Terminal's preferences, set it to "Default login shell," to prevent your login shell from being overridden:

Terminal's settings

Also, make sure the "Run command" checkbox is not checked in the Shell tab of your profiles' settings:

Profile settings

Relinquish answered 14/4, 2017 at 18:50 Comment(2)
the general settings - as of right now 2021 december - have changedCatanzaro
@CharlieParker: Terminal preferences wouldn't change based on a date; they might change based on a revision, but not on a date.Fix
A
11

Just type in any terminal you have open:

echo $0

And the name of the terminal will appear:

enter image description here

Adiabatic answered 1/2, 2022 at 14:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.