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
Depending on your shell implementation (e.g. Busybox vs. grown-up) the [ operator might start a process, changing $?.
[
$?
Try
getent passwd $1 > /dev/null 2&>1 RES=$? if [ $RES -eq 0 ]; then echo "yes the user exists" else echo "No, the user does not exist" fi