转至:https://www.cnblogs.com/gaohongyu/articles/12072594.html
#!/bin/bash #Author:GaoHongYu #QQ:1061767621 #Time:2019-12-19 02:47:09 #Name:login.sh #Version:V1.0 FILE_PATH=/root/user_list read -p "Please enter user name:" user grep -w $user $FILE_PATH &> /dev/null if [ $? -eq 0 ];then echo -n "Please enter passwd:" read -s passwd password=$(grep -A 1 $user $FILE_PATH|tail -1) if [ $passwd == $password ];then echo echo "Land successfull" else echo echo "Wrong password" fi else echo "${user} user not exist " read -p "Whether to create users,To create a user enter y,To exit press q:" choose if [ $choose == 'y' ];then read -p "Please enter user name:" new_user grep -w $new_user $FILE_PATH &> /dev/null if [ $? -eq 0 ];then echo "$new_user already existed" else echo "$new_user" >> $FILE_PATH read -p "Please $new_user enter passwd:" new_passwd echo "$new_passwd" >> $FILE_PATH echo "User $new_user creating successful" fi elif [ choose == 'q' ];then echo "exit program" exit fi fi
测试:
作者: 高宏宇
出处:https://www.cnblogs.com/gaohongyu/articles/12072594.html
版权:本文采用「署名-非商业性使用-相同方式共享 4.0 国际」知识共享许可协议进行许可。