?? add
字號:
#! /bin/sh -record_file=passwdadd_file=adddelete_file=deleteclearecho " 用戶信息增加情況"echo "========================================== " echo "輸入用戶的具體情況" while true #用戶名 echo "username:" read user_name;do if (test -z "$user_name") #-z 長度為0成真|判空方法2 "$user_name" = " " then echo "你還沒有輸入用戶名" continue elif echo $user_name>temp grep -qv "[a-zA-Z0-9]" temp then echo "輸入的是無效的用戶名 " rm -f temp elsecase $user_name in[a-zA-Z]*) if (awk -F: '{print $1}' $record_file|grep -wq $user_name)thenecho "該用戶已經存在"continue echo " "elsebreak fi;;*)echo "用戶名只能是字母或者下劃線開頭" ;;esacfi donewhile true #密碼dostty -echo #輸入不可見 echo "password:" read passwd1 if (test -z $passwd1) #輸入不可見方法2 read -ersthen echo "還未輸入密碼,再來一次 "continueelif (test `expr length $passwd1` -lt 6 ) #-lt 小等于 then echo "密碼長度不足6位,請重新輸入"continuefi#elif#( echo $passwd1>temp # grep -qv "[a-zA-Z]" temp||grep -qv "[0-9]"#)#then#echo "弱密碼,為了您的密碼安全是否重新輸入?(Y或N)"#read ans#case "$ans" in#y)continue;;#Y)continue;;#n)break;;#N)break;;#*)echo "請輸入Y或N"#continue;;#esacif(echo $passwd1|grep -q "^[a-zA-Z]*$") || (echo $passwd1|grep -q "^[0-9]*$")thenecho "輸入的是弱密碼"echo "是否要重新輸入?(Y或N)"read ycase $y iny|Y)continue;;n|N)echo "";;*)echo "輸入錯誤重新輸入"continueesacfi echo "password again:" read passwd2 if (test -z $passwd2) then echo "還未輸入,重新來一次 " continue elif (test $passwd1 != $passwd2) then echo "兩次輸入不相同,請重新輸入 "continue else stty echo #撤銷輸入不可見 break fidonewhile true #用戶IDdo echo "user ID:" read uidif (test -z $uid)thenecho " 沒有鍵入ID,請再次輸入"continueelif( echo $uid>temp grep -q "[^0-9]" temp)then echo "無效ID"elif( test "$uid" -lt "500") #判空方法2 "$uid" = " "then echo "用戶ID需要大于500,請再次輸入" continueelse breakfidonewhile true #組IDdo echo "group ID:" read gidif(test -z $gid)thenecho " 沒有鍵入ID,請再次輸入" continueelif ( echo $gid>temp grep -q "[^0-9]" temp)thenrm -f tempecho " 無效ID"else breakfidonewhile true #用戶全名 echo "user fullname:"read full_name do if (test -z "$full_name") then echo "你還沒有輸入用戶全名" continue elif echo $full_name>temp grep -qv "[a-zA-Z0-9]" temp then rm -f /root/07zsb-02-28/temp echo "輸入的是無效的用戶全名 " elsebreak fi done # echo "user todd:" #主目錄 # read user_todd while truedo echo "user shell:" read user_shell if (test -z $user_shell) then echo "沒有輸入!請再次輸入" continue elif case $user_shell in bash)break;; csh)break;; kash)break;; sh)break;; esac then echo "輸入的shell名不在本系統范圍內! " else break fidoneclearecho " 用戶信息增加情況"echo "========================================== " echo " user name : $user_name "echo " user ID : $uid "echo " group ID : $gid "echo " full name : $full_name "echo " shell : $user_shell"while true #保存用戶信息do echo " " echo "增加這個用戶嗎?(Y or N)" read answer1if (test -z $answer1)then echo "還未輸入,請輸入Y或N "else case $answer1 in y)echo "$user_name: :$uid:$gid:$full_name: :$user_shell ">> $record_filebreak;; Y)echo "$user_name: :$uid:$gid:$full_name: :$user_shell ">> $record_filebreak;; n)break;; N)break;; *)echo "請重新輸入Y或N" continue;; esacfidonewhile true #詢問是否增加新用戶doecho "還要繼續添加新用戶嗎?(Y or N)"read answer2if (test -z $answer2)then echo "還未輸入,請輸入Y或N "else case $answer2 in y) clear sh $add_file;; Y)clear sh $add_file;; n)sh menu;; N)sh menu;; *)echo "請重新輸入Y或N" continue;; esacfidone
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -