Linux 查看用户默认登录shell的*nix命令是什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11059067/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the *nix command to view a user's default login shell
提问by k107
What is the *nix command to view a user's default login shell?
查看用户默认登录 shell 的 *nix 命令是什么?
I can change the default login shell with chsh
, but I don't know how to get what is the user's default shell.
我可以使用 更改默认登录外壳chsh
,但我不知道如何获取用户的默认外壳。
Pseudocode
伪代码
$ get-shell
/usr/bin/zsh
采纳答案by Todd A. Jacobs
The canonical way to query the /etc/passwdfile for this information is with getent
. You can parse getent
output with standard tools such as cut
to extract the user's login shell. For example:
查询/etc/passwd文件以获取此信息的规范方法是使用getent
. 您可以getent
使用标准工具解析输出,例如cut
提取用户的登录 shell。例如:
$ getent passwd $LOGNAME | cut -d: -f7
/bin/bash
回答by timos
The login shell is defined in /etc/passwd
. So you can do:
登录外壳在/etc/passwd
. 所以你可以这样做:
grep username /etc/passwd
回答by Lucas
I think what you are looking for is this:
我想你要找的是这个:
#!/bin/bash
grep "^" /etc/passwd | cut -d ':' -f 7
Save that as get-shell
somewhere in your path (probably ~/bin) and then call it like:
将其另存为get-shell
路径中的某个位置(可能是 ~/bin),然后将其命名为:
get-shell userfoo
回答by user1460011
The command is finger
.
命令是finger
.
[ken@hero ~]$ finger ken
Login: ken Name: Kenneth Berland
Directory: /home/ken Shell: /bin/tcsh
On since Fri Jun 15 16:11 (PDT) on pts/0 from 70.35.47.130
1 hour 59 minutes idle
On since Fri Jun 15 18:17 (PDT) on pts/2 from 70.35.47.130
New mail received Fri Jun 15 18:16 2012 (PDT)
Unread since Fri Jun 15 17:05 2012 (PDT)
No Plan.
回答by nilsocket
SHELL
variable is used to represent user's current shell
SHELL
变量用于表示用户当前的shell
echo $SHELL