Finding Truth with ps -p $$
Parent - children process confusion in SHELL
Confusing Behaviour in Shell
SHELL does not reflect the currently running shell. If you launch bash inside a zsh session:
zsh
echo $SHELL # → /bin/zsh ( says zsh! )
echo $$ # → 3429
bash
echo $SHELL # → /bin/zsh ( STILL says zsh! )
echo $$ # → 5102 ( new PID — you're in bash now )$SHELL stayed the same because it’s just an inherited environment variable — it was set at login and never updated. $$ changed because a new process actually started.
Process inheritance (specifically environment inheritance)
When you ran:
bashThe current shell (
zsh) performed a fork()The child process executed bash
The child inherited the environment variables from the parent
So $SHELL stayed /bin/zsh because :
Environment variables are inherited from the parent process to the child process unless explicitly changed.
ps -p $$
zsh
ps -p $$
# shell expands this first $$ -> PID
ps -p 5102then it pick the process with PID - 5102
ps -p $$
# Ground Truth
PID TTY TIME CMD
5102 ttys003 0:00 bash “Like father, like son.”


