Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there more elegant way to find out what's another user's default shell (assuming that I have root privileges and using GNU/Linux)? I'm aware that I can get the answer by looking/parsing/greping/etc /etc/passwd, but there must be an utility (such as 'id' or 'chsh') that has a switch that prints this information to stdout.

It would be nice to run something like id --shell username to get the answer instantly.

EDIT: I see that first answers to my question can be categorized under 'parsing/looking/greping' /etc/passwd, so I'd like to emphasize that I'm aware that there are many ways to do this (shell on-liners, functions, scripts...), but that's not what I'm asking.

I'd like to know if some of standard tools that come preinstalled with most GNU/Linux distributions or tools that are part of coreutils have this feature.

share|improve this question
    
No, there's no such utility - why there should be one in first place, if shell oneliner can do it reliably? –  Szymon Szydełko Jul 4 '13 at 16:01
    
It doesn't have to be an utility just for this single purpose. Then again, we have 'groups' command that fetches similar information even if there's a way to to get the same information with shell oneliners :-) –  wolfyer Jul 4 '13 at 16:09

3 Answers 3

The finger command reports the shell for a user with the -l option

finger -l user

but you'll still need to do further processing e.g.

finger -l user | awk '/Shell:/ {print $4}'

if you just want the shell field

share|improve this answer

I don't know of any utility but adding this function to your ~/.bashrc seems elegant enough:

function usershell(){
 awk -F: -v name=$1 '$1==name{print $NF}' /etc/passwd
}

You can then call it on a user name. For example:

$ usershell terdon
/bin/bash
share|improve this answer
    
Well, the end result is what I'm looking for, but it would be nice to have the same or similar output from one of coreutils tools, so that you can get the information right away when you log in to the computer/server for the first time. –  wolfyer Jul 4 '13 at 17:44

I think you're looking for getent

getent passwd username | cut -d: -f7
share|improve this answer
    
Without parsing the output, with getent I get the same result when I execute "grep username /etc/passwd". So far, I like your suggestion most as it has shorter syntax than grep. If getent had short switches for databases, that would be exactly what I'm looking for. And before anyone mentiones bash aliases, please read my other comment :-) –  wolfyer Jul 4 '13 at 17:56
    
If your system is set up with NIS or LDAP or some other centralized directory, the user may not appear in /etc/passwd. –  glenn jackman Jul 4 '13 at 18:09
    
Yes, I'm aware of that. I rarely work on systems that use LDAP, but thanks for pointing this one out. –  wolfyer Jul 4 '13 at 18:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.