What is the *nix command to view a user's default login shell

LinuxShellUnix

Linux Problem Overview


What is the *nix command to view a user's default login shell?

I can change the default login shell with chsh, but I don't know how to get what is the user's default shell.

Pseudocode

$ get-shell
/usr/bin/zsh

Linux Solutions


Solution 1 - Linux

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:

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

Solution 2 - Linux

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.

Solution 3 - Linux

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

grep username /etc/passwd

Solution 4 - Linux

I think what you are looking for is this:

#!/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:

get-shell userfoo

Solution 5 - Linux

SHELL variable is used to represent user's current shell

echo $SHELL

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionk107View Question on Stackoverflow
Solution 1 - LinuxTodd A. JacobsView Answer on Stackoverflow
Solution 2 - Linuxuser1460011View Answer on Stackoverflow
Solution 3 - LinuxtimosView Answer on Stackoverflow
Solution 4 - LinuxLucasView Answer on Stackoverflow
Solution 5 - LinuxnilsocketView Answer on Stackoverflow