共计 782 个字符,预计需要花费 2 分钟才能阅读完成。
#!/bin/bash
if [$UID -ne 0];then
echo "oline root"
exit 9
fi
Path=/etc/user.conf
if [! -f $Path];then
touch $Path
fi
chmod 700 $Path
if [2 -ne $#];then #-eq == -ne !=
echo "you must be input user and password!"
exit 2
fi
Age=$1
User=$2
if [0 -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 -w "$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 true"
exit 3
fi
}
funDeluser(){
funCheckUser
if [$? -eq 0];then
echo "no find this is $User"
else
sed -ri /^$User$/d $Path
exit 4
fi
}
funSearch(){
funCheckUser
if [$? -eq 0];then
echo "there is a $User name is NO find!"
else
echo "thers is a $User name is true"
fi
}
case $Age in
-add)
funAddUser
;;
-del)
funDeluser
;;
-search)
funSearch
;;
*)
echo "USAGE: sh adduser (-add|-del|-search) username!"
;;
esac
正文完
发表至: 未分类
2018-04-20