查看用户默认登录 shell 的 *nix 命令是什么?
我可以用 更改默认登录 shell chsh
,但我不知道如何获取用户的默认 shell。
伪代码
$ get-shell
/usr/bin/zsh
查询/etc/passwd文件以获取此信息的规范方法是使用getent
. 您可以使用标准工具解析getent
输出,例如cut
提取用户的登录 shell。例如:
$ getent passwd $LOGNAME | cut -d: -f7
/bin/bash
命令是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.
登录外壳定义在/etc/passwd
. 所以你可以这样做:
grep username /etc/passwd
我认为您正在寻找的是:
#!/bin/bash
grep "^$1" /etc/passwd | cut -d ':' -f 7
将其保存get-shell
在路径中的某个位置(可能是 ~/bin),然后像这样调用它:
get-shell userfoo
SHELL
变量用于表示用户当前的shell
echo $SHELL