Linux commands: Vim Edit script Exercise

Source: Internet
Author: User

Practice One:

Add or remove users by accepting user-entered user names,./adminuser.sh --add User1,user2,jack,donggen means adding 4 users who are automatically entered, with the same password as the username entered

--del means to delete user-established user, and, the user that exists, need to prompt already exist the user that cannot add, does not exist

This user is not present when the deletion is prompted.

#!/bin/bash

#program:

#练习接收用户输入的用户名, decide to delete or add users

#history Donggen 2016-10-22-22:50

Path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bash

Export PATH

If [$#-lt 1]; Then

echo "USAGE: + ARG"

Exit 5

Fi

if [= = = "--add"]; Then

For I in ' echo ' | Sed ' s/,//g '; Do

If ID $I &>/dev/null; Then

echo "$I is exist"

Else

Useradd $I &>/dev/null

echo "$I" | passwd--stdin $I &>/dev/null

echo "$I is add successful"

Fi

Done

elif [= = = "--del"]; Then

For I in ' echo ' | Sed ' s/,//g '; Do

If ID $I &>/dev/null; Then

Userdel-r $I

echo "$I is del successful"

Else

echo "NO such $I"

Fi

Done

Else

echo "UNknown symbol"

Fi

Exercise two,

Write a script that uses a combination test

if [$ = ' Q '-o $ = ' Q '-o $ = ' quit '-o $ = ' quit ']; Then

Ehco "Quiting ..."

Else

echo "Unknown symbol"

Fi

This article is from the "Learn Linux history" blog, please be sure to keep this source http://woyaoxuelinux.blog.51cto.com/5663865/1864827

Linux commands: Vim Edit script Exercise

Related Article

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.