Monday, November 28, 2022

Matching username from input with /etc/passwd without grep

 #/bin/bash

echo "enter username to check"

read username

match=0

for line in `cat /etc/passwd`

do


if test `echo $line | cut -d ":" -f 1| cut -d "," -f 1` == $username ;

then

#match=$(($match+1))

#let "match=match+1"

#let "match++"

((match++))

fi


done

if [ $match -gt 0 ];

then

echo "$username is valid because match is $match"

else

echo "$username is not valid because match is $match"

fi

No comments:

Post a Comment