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