In Julia Evans' How to add a directory to your PATH, she shows off an odd-looking command for determining what shell (e.g. bash or zsh) you are currently running.
$ ps -p $$ -o pid=,comm=
38105 -zsh
I already know I'm running zsh
, but I thought this command was interesting
enough to dig into and break down.
- The
ps
command lists processes that "have controlling terminals" - The
$$
is a special shell variable representing the PID of the current process (tryecho $$
) - The
-p
flag allows you to specify a PID forps
to grab, in this case, the$$
PID - The
-o
flag allows us to specify the output format, such as the PID and command name - The
=
afterpid
andcomm
tellps
to exclude headers from the output
Additionally, I noticed that it output -zsh
(not just zsh
). That leading
hyphen seems to indicate that this zsh
process is a login
shell. That means it was the
process used to initiate an interactive shell session and something like the
.zprofile
would have been sourced as part of that.