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
Using sed:
username="alice" if [ `sed -n "/^$username/p" /etc/passwd` ] then echo "User [$username] already exists" else echo "User [$username] doesn't exist" fi