The command or path to the currently running shell is stored in the environment variable $0
. To see its value, use:
echo $0
This outputs either your currently running shell or the path to your currently running shell, depending on how it was invoked. Some processing might be required:
prompt:~$ echo $0
/bin/bash
prompt:~$ sh
sh-4.0$ echo $0
sh
sh-4.0$ exit
exit
prompt:~$ /bin/sh
sh-4.0$ echo $0
/bin/sh
sh-4.0$
The $SHELL
environment variable contains the user's preferred shell, not necessarily the currently running shell.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…