标签:art 添加 user 删除 return 检查 turn sea format
#!/bin/bash
Path=/etc/user.conf
if [ ! -f $Path ];then
touch $Path
fi
chmod 644 $Path
if [2 -ne $# ];then
echo "usage:sh adduser {-add|-del|check}"
exit 1
fi
Age=$1
User=$2
if [ 1 -lt echo ‘$User‘ |grep -E "[^a-z,A-Z,0-9,_]" |wc -l ];then
echo "The age format is error"
exit 2
fi
funCheckUser() {
check=$(grep "$User" $Path |wc -l)
if [ $check -eq 0 ];then
return 0
else return 1
fi
}
funAddUser(){
funCheckUser
if [ $? -eq 0 ];then
echo "$User" >> $Path
else
echo "The user is having"
exit 3
fi
}
funDelUser(){
funChckUser
if [ $? -eq 0 ];then
echo "no user"
else
sed -ri /^$User/d $Path
exit 3
fi
}
funSearch(){
if [ $? -eq ) ];then
echo "no user match"
else
echo "$User is having"
fi
}
case $Age in
-add)
funAddUser
;;
-del)
funDelUser
;;
-check)
funCheck
;;
*)
echo "error formart"
;;
标签:art 添加 user 删除 return 检查 turn sea format
原文地址:http://www.cnblogs.com/tdtdttdd/p/6868695.html