热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

查看用户默认登录shell的*nix命令是什么-Whatisthe*nixcommandtoviewauser'sdefaultloginshell

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

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更改默认的登录shell,但是我不知道如何获得用户的默认shell。

Pseudocode

伪代码

$ get-shell
/usr/bin/zsh

4 个解决方案

#1


52  

The canonical way to query the /etc/passwd file 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。您可以使用标准工具(如cut)解析getent输出,以提取用户的登录shell。例如:

$ getent passwd $LOGNAME | cut -d: -f7
/bin/bash

#2


18  

The command is 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.

#3


6  

The login shell is defined in /etc/passwd. So you can do:

登录shell在/etc/passwd中定义所以你能做什么:

grep username /etc/passwd

#4


2  

I think what you are looking for is this:

我认为你在寻找的是:

#!/bin/bash

cat /etc/passwd | grep $1 | cut -d ':' -f 7

EDIT: @jrrs recommended this version as an improvement... I agree...

编辑:@jrrs推荐这个版本作为改进…我同意……

#!/bin/bash

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

Save that as get-shell somewhere in your path (probably ~/bin) and then call it like:

将其保存为路径中的某个地方(可能是~/bin),然后这样调用:

get-shell userfoo

推荐阅读
author-avatar
书友73892718
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有