shell整理(35)====模拟用户登录的打印菜单脚本

前端之家收集整理的这篇文章主要介绍了shell整理(35)====模拟用户登录的打印菜单脚本前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

(一)打印一个菜单,接受一个输入,如果没有这个用户就创建用户和密码,将创建的用户和密码写入到一个文件,如果文件中有就模拟一个用户登录,要求用户名任意,可以是(^$ ^q ),密码分两种可以是空密码,也可以是任意长度的密码。

shell代码如下:

#!/bin/bash

create_user(){
read-p"PlzInputName:"name
catfile|grep$name&>/dev/null
[$?-eq0]&&echo"Theuserisexise"&&exit0
if[-z$name];then
echo"noexise"&&exit0
fi
read-p"PlzInputPasswd:"passwd
read-p"PlzInputPasswdAgain:"passwd1
if[["$passwd"!="$passwd1"]];then
echo"passwdnotright"&&exit0
fi
if[!-z"$passwd"];then
echo"$name"$passwd"">>file
echo"successfully!"
fi
if[-z"$passwd"];then
echo"$name""">>file
echo"successfully!"
fi

}
login(){

read-p"PlzInputname:"name
a="`catfile|awk'$1=="'$name'"'|cut-d''-f2-`"
b=`echo"$a"|sed's///g'`
catfile|awk'$1=="'$name'"'&>/dev/null
if[$?-eq0];then
read-p"PlzInputyourpasswd:"passwd
c=`echo$passwd|sed's///g'`

if[["$b"="$c"]];then
echo"successfully!"
else
echoerror
fi
else
echo"notuser;plztocreiate"
fi
}
haha(){
case$ccin
1)
create_user
;;
2)
login
;;
3)
exit0
;;
*)
exit1
;;
esac

}
cat<<EOF
=========pleasechoice=========
1)create_user
2)login
3)exit

EOF
read-p"Choice:"cc
haha


这个脚本虽然很简单,但是我也根据不同的情况调试了好久.

原文链接:https://www.f2er.com/bash/390273.html

猜你在找的Bash相关文章