Introduction
Linux
andUnix
All available out of the boxshell
. Can be foundbash (Bourne Again shell)
、ksh (Korn shell)
、csh (C shell)/tcsh (TC shell)
、sh (Bourne shell)
Wait for default installationshell
. But how do I check which one I am usingshell
?
method
Use $0 (best way)
echo $0 # $0 Contains the name of the currently running shell or script# If run in an interactive shell, it displays the shell name (bash, zsh, etc.)# If you run the script, it will display the file name of the script
Shows the currently running
shell
The name ofSample output:
/bin/bash、zsh、fish
Use $SHELL (default login Shell)
echo $SHELL
- Show the default settings of the user
shell
(Not necessarily the current oneshell
)
Use the ps command
ps -p $$ # $$ Save the process ID (PID) of the current shell session# If used in a script, it provides the PID of the script shell
Show current
shell
The processSample output
PID TTY TIME CMD
Use the ps command to output shell names directly
ps -o comm= -p $$
Use echo $0 with base name
basename "$0" # Show shell names without full path
Use readlink to get
readlink /proc/$$/exe
View all shells installed on the system
cat /etc/shells
Sample output
/bin/bash /bin/csh /bin/dash /bin/ksh /bin/sh /bin/tcsh /bin/zsh
Use grep to view
grep "^$USER" /etc/passwd
Use lsof to view
lsof -p $$
This is the end of this article about the method of viewing the current shell used by Linux. For more related content about viewing the current shell used by Linux, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!