shell脚本:简单考试

#首页:登录,注册

read -p "
---------->考试系统<-------------
  
    登录--------------1
    
    注册--------------2

    退出--------------3

" a;
#登录界面:
A () {
echo "
------------>欢迎<--------------
";
read -p "  用户名:" name;
if [ -z $name ] ;then
    read -p "用户名不能为空!";
    clear ;
    A;
else
    nm=`cat /root/shell/han/1.txt | grep $name | cut -d " " -f 1`;
    name=$nm;
    if [ -z $name ] ;then
            echo "             用户不存在!"
            echo "";
            /root/shell/han/first.sh ;
    else
            echo;
            echo;
            read -s -p "  密码:" passwd;
            pw=`cat /root/shell/han/1.txt | grep $name | cut -d " " -f 2`;
if [ $passwd == $pw ] ;then
                    echo "           登录成功!";
                    /root/shell/han/a.sh ;
            else
                    read -p "           密码错误!";
                    clear ;
                    A;
            fi
    fi
fi
}

#注册页面:用户名、密码

B () {
echo "
----------注册----------
"
echo ;
read -p "请输入用户名:" name;
if [ -z $name ] ;then
    read -p "用户名不能为空!";
    clear ;
    B;
else
    nm=`cat /root/shell/han/1.txt | grep $name | cut -d " " -f 1`;

    if [ -z $nm ] ;then
            read -s -p "请输入密码:" passwd;
            echo "$name $passwd" >>1.txt
            read -p "注册成功!请登录";
            /root/shell/han/first.sh ;
else
            read -p "用户已存在!";
            clear ;
            B;
    fi
fi
}

#判断:

if [ $a == 1 ] ;then
    clear ;
    A;
    elif [ $a == 2 ] ;then
            clear ;
            B;
            elif [ $a == 3 ] ;then
                    read -p "已退出!";
                    clear ;
else
    echo "请选择正确选项!"
    ./first.sh;
fi

#副页
#考试系统:

clear ;
read -p "
-------------->高一(三)班<----------------
<-----------课程选择------------->
    语文-------------------1
    数学-------------------2
    英语-------------------3
    物理-------------------4
    化学-------------------5
    生物-------------------6
            退学+.+--------7
" a;

A () {
    i=1;
    j=6;
    z=0;
 read -p " `cat /root/shell/han/$q/$i` " a1;
       while [ $i -le 5  ] ;do
                    read -p " `cat /root/shell/han/$q/$i` " a1;
            if [ $a1 = "`cat /root/shell/han/$q/$j`" ] ;then
                    echo "回答正确!";
                   z=0;
                    z=$(expr $z + 1);
                    i=$(expr $i + 1);
                    j=$(expr $j + 1);
                    echo $z
            else
                    echo "回答错误!";
                    i=$(expr $i + 1);
                    j=$(expr $j + 1);
            fi
       done
    echo $z
}


case "$a" in
      1) #语文
            clear ;
            if [ $a = 1 ] ;then
            q=1;
            A;
            /root/shell/han/a.sh ;
            fi
    ;;
    2)#数学b:
            clear ;
            if [ $a = 2 ] ;then
            q=2;
            A;
            /root/shell/han/a.sh ;
            fi
    ;;

    3)#英语:
            clear ;
            if [ $a = 3 ] ;then
			q=3;
            A;
            /root/shell/han/a.sh ;
            fi
    ;;
    4)#物理:
            clear ;
            if [ $a = 4 ] ;then
            q=4;
            A;
            /root/shell/han/a.sh ;
            fi
    ;;
    5)#化学:
            clear ;
            if [ $a = 5 ] ;then
            q=5;
            A;
            /root/shell/han/a.sh ;
            fi
    ;;

    6)#生物:
    		clear ;
            if [ $a = 6 ] ;then
            q=6;
            A;
            /root/shell/han/a.sh ;
   fi
    ;;

    7)#退学;
            clear ;
            echo "把你家长叫来!我要谈话!";
             /root/shell/han/first.sh ;
    ;;

    *)
            clear ;
            echo "请联系班主任!"
            /root/shell/han/first.sh ;
    ;;
esac
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值