Você pode usar isto:
#!/usr/bin/env bash
anotherUser() {
read -p "Add another user? [y/n]" -n1 yn
yn='echo $yesno |tr '[:upper:]' '[:lower:]''
if [[ "$yn" = "y" ]]; then
checkUser
fi
exit
}
checkUser() {
while :
do
read -p "Enter user: " userName
read -s -p "Enter password : " userPass
id -u "$userName" >/dev/null 2>&1
if [ $? -eq 0 ] ; then
echo "User exists"
anotherUser
else
echo adduser "$userName"
printf "User %s has been added\n" "$userName"
exit
fi
done
}
checkUser