I'm making a script that add an user, deletes an user and change password of an user passed as parameter ($1). I want to check if the user exists, so I can control this better. I know this question have been asked a lot of times, I've been googling this before, but really, these solutions didn't work for me, I don't know which is my mistake, so sorry.
This is my code:
#!/bin/bash
existe=$(grep -c '^$1:' /etc/passwd)
if [ $existe -eq 0 ]; then
echo "The user $1 exists"
echo ""
else
echo "The user $1 does not exist"
echo ""
fi
I've tried the ">/dev/null" solution, the "getent" thing... Agh... No matter what I do, the user always exists, and the code I pasted here is the last one I was trying.
Can you help me? ^^ Thanks in advance.