On most systems, I use bash as shell, but not all systems have it, for instance the shell.xs4all.nl server uses tcsh and ESXi 4+ uses a very limited ash shell from busybox (ESX 4 had bash though).
There is this huge script that covers many shell and operating system versions (even DOS, Windows) and interpreters (python, ruby, php, etc) what shell is this which I got through Stéphane Chazelas‘s answer in linux – determine shell in script during runtime – Unix & Linux Stack Exchange
I wanted a shorter thing that works in current Linux, BSD, OS X and ESXi versions.
Some very short scripts are less reliable, for instance echo $SHELL
looks nice, but isn’t always set.
Similar for echo $0
which will fail for instance if it shows as sh
but in fact is a different shell in disguise.
This works for bash, tcsh and busybox sh, is a bit more precise than getting $0
. It’s based on HOWTO: Detect bash from shell script – Stack Overflow:
lsof -p $$ | awk '(NR==2) {print $1}'
But on ESXi it shows this because lsof doesn’t take any parameter there and just dumps all information:
----------+---------------------+---------------------+--------+------------------
It’s because lsof on ESXi always shows this header where Cartel and World aren’t exactly well documented:
Cartel | World name | Type | fd | Description
----------+---------------------+---------------------+--------+------------------
Empirically for non VM related processes, it looks like the Cartel
is the PID
and World name
the command
.
On Linux and BSD based systems, the header looks like this, so command
and PID
are reversed in ESXi:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
This command then works on both ESXi, OS X, Linux and BSD assuming you can word search for the PID and noting that PID/command will be reversed on ESXi as compared to OSX/Linux/BSD:
lsof -p $$ | grep -w $$ | awk '(NR==2) {print $1,$2}'
–jeroen
Like this:
Like Loading...