Simple statement enables user to add, delete

Source: Internet
Author: User

Simple statement enables user to add, delete
Guide I sue small white, a just entered the Linux world of cabbage. Recently has been through the "Linux on this study" to learn Linux knowledge, a few days ago on the Internet to see a general user Add, delete shell script commands, when they do not write, but the title recorded down! Later, through the study of "Linux should learn", completed the topic required. Hope that the need to see, at the same time there is not the right place to hope that Daniel can make a message!
Title requirements:Edit shell script commands to add and delete ordinary users.
Requirements:
1. Add (delete) The normal user is to query whether a normal user already exists.
2. Add (delete) to implement circular inquiry The specific code is as follows:
#!/bin/bashread-p "Do you want to add users?" Yes (0) No (1) "USERADD  

Select action Type--add user/delete user

Add user code
If [$USERADD-eq 0]thenc=1while [$C-eq 1]doread-p "Please enter add account name:" UNAME  #添加用户名 #id $UNAME &>/dev/null    # See if a user exists with an # if [$?-eq 0]thenecho] Account! "Else Read-p" Please enter the Add account password: "PASSWD     #添加密码 #useradd $UNAME &>/dev/null      #创建用户 #echo" $PASSWD "| passwd--stdin $UNAME &>/dev/null    #创建用户密码 #

Note Do not add spaces in the $PASSWD, otherwise the password will contain spaces!

If [$?-eq 0]then Echo "$UNAME created successfully! "Elseecho" $UNAME creation failed! "Fifiread-p" Do you still want to add? Yes (1) No (0) "C   #设定变量" C "to implement the Delete code loop execution #done
Delete user code

Elsedel=1while [$DEL-eq 1]doread-p "Please enter the user name to delete:" UNAME   #要删除的用户名 #id $UNAME &>/dev/nullif [$?-eq 0]  # Delete the user query if there is #thenuserdel-r $UNAME     #删除用户 #echo "$UNAME Delete succeeded! "Elseecho" User not found $uname! "Firead-p" Do you want to continue? Yes (1) No (0) "Del   #设定变量" del "to implement the Delete code loop execution #donefi

Free to provide the latest Linux technology tutorials Books, for open-source technology enthusiasts to do more and better: http://www.linuxprobe.com/

Simple statement enables user to add, delete

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.