Topic
Write a script
1. Pass a parameter to the script, this parameter is the user name;
2. If the user exists, perform the following tasks
* If the user's ID number is less than 500, display it as an administrator or system user;
* Otherwise, display it as a normal user;
3. If the user does not exist, add it;
Answer
#!/bin/bashUsername= $if["$username"=""]; Then Echo "Please input a username" Exit 1fiifId$username&>/dev/null; Thenuserid=$ (id-u$username)if[$userid -lt -]; Then Echo "$username is a admin user" Else Echo "$username is a normal user" fiElseUseradd$username if[ $?-eq 0]; Then #判断用户是否添加成功 Echo "ADD user $username." Else Echo "Can not add $username." fifi
Description
id $username &> /dev/null
The redirect behind here is to eliminate the useless output
Copyright NOTICE: This article is Orangleliu (http://blog.csdn.net/orangleliu/) original article, the article reproduced please declare.
"Shell scripting Exercises" to determine user presence and user type