Good morning, I have a problem with the following shell script.
Do I need to ask again if the user is already registered in the system? If I put a pause after <echo "already exists"> it gives me an error, and if I put an output, it leaves the script completely. I've also tried to put a real one after <echo -n "Do you want to enter a user? (Y / N):"; read answer> but it does not work either
The purpose of the script is to request a username, if it does not exist, and then create it. But if it already exists ask for another name.
Thank you.
Do I need to ask again if the user is already registered in the system? If I put a pause after <echo "already exists"> it gives me an error, and if I put an output, it leaves the script completely. I've also tried to put a real one after <echo -n "Do you want to enter a user? (Y / N):"; read answer> but it does not work either
The purpose of the script is to request a username, if it does not exist, and then create it. But if it already exists ask for another name.
Thank you.
Code:
#!/bin/bash
echo -n "Do you want to enter a user? (y/N): "; read answer
if [ $answer = 'y' ]; then
echo "Enter the user: "
read USER
if grep -qi "^$USER:" /etc/passwd
then
echo "already exists"
else
echo "does not exist"
fi
elif
[ $answer = 'N' ]; then
exit
fi
Last edited: