找到现实生活中的名字和csh登录shell

时间:2013-05-07 14:13:50

标签: csh

当我在etc / passwd文件中找到现实生活中的名字时,如何单独输出csh shell登录信息:

awk -F":" ' {print $5} /etc/passwd

我需要找到拥有csh登录shell的用户

1 个答案:

答案 0 :(得分:0)

/bin/sh
cat /etc/passwd | grep -w csh | while read line
do
  user=`echo $line | awk -F: '{print $1}'`
  echo User $user is using csh
done

或者按照要求在没有grep的情况下在一行上执行此操作(有关更多示例,请参阅此答案:Only print lines where the second field matches some criteria

但简短版本是:

awk -F: '$7 == "/bin/csh" {print $5}' /etc/passwd