Linux Shell 实现的学生信息管理系统,别问我为什么这么无聊,因为课程设计需要!!!

#!/bin/bash
log_in_operate(){
printf "1、输出学生信息\n"
printf "2、查询学生信息(姓名)\n"
printf "3、修改学生信息\n"
printf "4、添加学生信息\n"
printf "5、删除学生信息\n"
printf "6、退出登陆\n"
read sign
case $sign in
1)
all_info
;;
2)
find_stu
;;
3)
change_info
;;
4)
add_info
;;
5)
delect
;;
6)
out_log
;;
esac
}
main_log()
{
    printf "1、登陆\n"
    printf "2、注册\n"
    read m
    if [ $m -eq 1 ] 
    then
    log_users
    else
    if [ $m -eq 2 ] 
    then
    register_users
    else
    printf "输入有误,重新输入\n"
    main_log
    fi
    fi
}

register_users(){
    printf "输入用户名:\n"
    read name
    printf "输入密码:\n"
    read pass
    printf "再次确认密码:\n"
    read repass
    if [ $pass != $repass ]
    then
    printf "两次输入有误\n"
    register_users
    else
    reg="$name $pass"
    #写入文件
    echo $reg >> "\Users\dengnici\Desktop\users.dat"
    printf "注册成功!\n"
    main_log
    fi
}
log_users(){
    printf "输入账户"
    read account
    printf "输入密码"
    read pass
    File="\Users\dengnici\Desktop\users.dat"
    users="$account $pass"
    #cat $File | while read line
    #do
    #if [ "$users" = "$line" ]
    #then
    #printf "登陆成功!\n"
    #export sign=1
    var=$(grep "$account" "$File")
    if [ "$users" = "$var" ]
    then
    log_in_operate
    else
    printf "用户名或密码错误\n"
    main_log
    fi

}
add_info(){
    printf "输入学号:\n"
    read num
    #判断学号是否存在
    var=$(grep "$num" "\Users\dengnici\Desktop\stu.dat")
    File="\Users\dengnici\Desktop\stu.dat"
    cat $File | while read line
    do
    if [ "$var" = "$line" ] 
    then
    printf "学号存在!\n"
    log_in_operate
    break
    fi
    done
    printf "输入姓名:\n"
    read name
    printf "输入年龄\n"
    read age
    printf "输入性别\n"
    read sex
    if [ "$sex" != "男" -a "$sex" != "女" ]
    then
    printf "性别输入有误!"
    add_info
    fi
    printf "输入电话\n"
    read phone_num
    student="$num $name $age $sex $phone_num"
    printf "添加成功!\n"
    echo $student >> "\Users\dengnici\Desktop\stu.dat"
    log_in_operate
}
delect(){
    printf "请输入您想删除学生的学号"
    read num
    if [ ! -f "\Users\dengnici\Desktop\stu.dat" ]
    then
    printf "文档为空,请先添加!\n"
    else
    grep "$num"  "\Users\dengnici\Desktop\stu.dat"> "\Users\dengnici\Desktop\null.dat"
    if [ $? != 0 ] 
    then
    echo "此人不存在!\n"
    else
    printf "删除成功!\n"
    cp "\Users\dengnici\Desktop\stu.dat" "\Users\dengnici\Desktop\stu.txt"
    grep -v $num "\Users\dengnici\Desktop\stu.txt" > "\Users\dengnici\Desktop\stu.dat"
    fi
    fi
    log_in_operate
}
#修改函数
change_info(){
printf "请输入名字:"
read name
grep "$name"  "\Users\dengnici\Desktop\stu.dat"> "\Users\dengnici\Desktop\null.dat"
    if [ $? != 0 ] 
    then
    echo "此人不存在!\n"
    change_info
    else
    cp "\Users\dengnici\Desktop\stu.dat" "\Users\dengnici\Desktop\stu.txt"
    grep -v $name "\Users\dengnici\Desktop\stu.txt" > "\Users\dengnici\Desktop\stu.dat"
    add_info
    printf "修改成功!\n"
    fi
    log_in_operate
}
find_stu(){
printf "请输入名字:"
read name
grep "$name"  "\Users\dengnici\Desktop\stu.dat"> "\Users\dengnici\Desktop\null.dat"
if [ $? != 0 ] 
then
printf "此人不存在!\n"
else
grep "$name"  "\Users\dengnici\Desktop\stu.dat"
fi
log_in_operate
}
all_info(){
    cat "\Users\dengnici\Desktop\stu.dat"
    printf "\n"
    log_in_operate
}

out_log(){
    main_log
}

main_log
Logo

更多推荐