Thursday, November 24, 2022

Check if an username is present in /etc/passwd using shell script

 #!/bin/bash
read -rep $'Please enter username\n' username
#echo "you have entered $username"
if [ `grep -c $username /etc/passwd` -eq 0 ]
then
echo "$username is invalid"
else
echo "$username is valid"
fi

No comments:

Post a Comment