Day 51: Listing your current shell

< 1 min read    22 Jun 2017    

How to find the current shell that you’re working in ?

  • echo $SHELL could work, but not reliable if you’re using bash within zsh/fish.
  • ps -p $$ - fish does not support this.
  • ps - Gives a list of running shells, and reliably the second last line gives the correct shell.

Sample:

1) Using inside default fish:

> ps
  PID TTY          TIME CMD
 7603 pts/17   00:00:00 fish
 8347 pts/17   00:00:00 ps

2) Using inside bash which is running inside fish:

> ps
  PID TTY          TIME CMD
 7603 pts/17   00:00:00 fish
 8521 pts/17   00:00:00 bash
 8708 pts/17   00:00:00 ps

3) Using inside bash inside zsh inside fish:

> ps
  PID TTY          TIME CMD
21845 pts/0    00:00:00 fish
22193 pts/0    00:00:00 zsh
22727 pts/0    00:00:00 bash
22728 pts/0    00:00:00 ps

Some rights reserved.

Leave a Comment