60

查看用户默认登录 shell 的 *nix 命令是什么?

我可以用 更改默认登录 shell chsh,但我不知道如何获取用户的默认 shell。

伪代码

$ get-shell
/usr/bin/zsh
4

5 回答 5

77

查询/etc/passwd文件以获取此信息的规范方法是使用getent. 您可以使用标准工具解析getent输出,例如cut提取用户的登录 shell。例如:

$ getent passwd $LOGNAME | cut -d: -f7
/bin/bash
于 2012-06-15T22:57:01.317 回答
24

命令是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.
于 2012-06-16T01:18:43.067 回答
11

登录外壳定义在/etc/passwd. 所以你可以这样做:

grep username /etc/passwd
于 2012-06-15T22:48:49.067 回答
3

我认为您正在寻找的是:

#!/bin/bash
grep "^$1" /etc/passwd | cut -d ':' -f 7

将其保存get-shell在路径中的某个位置(可能是 ~/bin),然后像这样调用它:

get-shell userfoo
于 2012-06-15T22:56:15.287 回答
1

SHELL变量用于表示用户当前的shell

echo $SHELL
于 2018-09-21T15:17:13.310 回答