Check Whether a User Exists

后端 未结 17 2024
清歌不尽
清歌不尽 2020-11-29 17:31

I want to create a script to check whether a user exists. I am using the logic below:

# getent passwd test > /dev/null 2&>1
# echo $?
0
# getent pa         


        
17条回答
  •  孤城傲影
    2020-11-29 17:40

    Script to Check whether Linux user exists or not

    Script To check whether the user exists or not

    #! /bin/bash
    USER_NAME=bakul
    cat /etc/passwd | grep ${USER_NAME} >/dev/null 2>&1
    if [ $? -eq 0 ] ; then
        echo "User Exists"
    else
        echo "User Not Found"
    fi
    

提交回复
热议问题