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

前端 未结 5 1246
刺人心
刺人心 2020-12-13 12:19

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

相关标签:
5条回答
  • 2020-12-13 12:38

    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.
    
    0 讨论(0)
  • 2020-12-13 12:40

    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
    
    0 讨论(0)
  • 2020-12-13 13:01

    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
    
    0 讨论(0)
  • 2020-12-13 13:01

    SHELL variable is used to represent user's current shell

    echo $SHELL
    
    0 讨论(0)
  • 2020-12-13 13:02

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

    grep username /etc/passwd
    
    0 讨论(0)
提交回复
热议问题