check new user with /etc/passwd

example

 
# useradd hello 


how to i suppose to do if hello is existed in passwd file?

the error will come out
 
user hello exist


so my question is if i do like

1
2
3
4
5
6
7
8
9
10
11
12
# Enter username: 
read username

//concept
if [ $username existed ]
then
     echo " error"
else
     ...
     ...
fi


i don't know how to code it. can someone teach?
He would, if he were using C/C++/etc. However, according to his threads on this topic, his homework is to write a shell script. Luckily, there are simple programs that do call getpwnam() and have exit status to test.

There must be Fora out there focused on basic shell scripting and less focused on the use of C++ to interact with UNIX-like system.
Topic archived. No new replies allowed.