Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
512 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...