Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
551 views
in Technique[技术] by (71.8m points)

unix - What shell am I in?

Is there a command to identify the name/type of current shell, the path to the shell binary, and the version of the shell?

I don't need all of that, but the more I can get, the better.

I want something that has the same feel of uname, pwd, whoami. Just a plain utility with a simple output. (which so far hasn't showed up :/ )

re ps

$ ps -o comm $$
COMM
-bash

Why -bash instead of the full path as it would be with everything else? What's the deal with the dash there?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...