测试shell
#! /bin/bash colour () { #格式为背景:前景m,主要实现屏幕颜色显示 case $1 in black_white ) #背景为黑色,前景为白色 echo -e "\033[40;37m" ;; black_green ) #背景为黑色,前景为绿色 echo -e "\033[40;32m" ;; black_cyan ) #背景为黑色,前景为青色 echo -e "\033[40;36m" ;; red_yellow ) #背景为红色,前景为黄色 echo -e "\033[41;33m" ;; yellow_blue ) #背景为黄色,前景为蓝色 echo -e "\033[43;34m" ;; esac } do_register() { echo "Input ID:" read ID if grep "$ID" users.db then echo "User is already exists! please Input other username:" do_register fi echo "Input Password:" read PSW echo "Reinput Password:" read PSWt if [ $PSW -eq $PSWt ] then echo "$ID2 $PSW"21 >>users.db echo "create success!" else echo "Two passwords are not the same!" echo "Register failed!" fi } do_login() { echo "ID PSW:" read ID read PSW if grep "$ID $PSW" users.db then do_Menu else echo "login error!" fi } do_entry() { echo "***************************************" echo "********欢迎使用学生管理系统*********" echo "****** 1.创建用户 2.登录用户 ******" echo "****** (请输入选择序号) *******" echo "***************************************" echo -e "---->您的选择:\c" read val case $val in 1)do_register;; 2)do_login;; esac } do_print() { echo "学号 姓名 年龄 性别 电话" cat stu.db } do_inquire() { colour black_white echo "Input ID or name:" read x if grep -w "$x" stu.db then echo "学号 姓名 年龄 性别 电话" else echo "The student does not exist!" fi } do_update() { colour black_cyan echo "Input The Student's ID:" read ID if grep -w "$ID" stu.db then echo "Input the updated information:" echo "学号 姓名 年龄 性别 电话" read ID name age sex phone echo "$ID $name $age $sex $phone" >>stu.db echo "Update completed!" else echo "The student does not exist!" fi } do_add() { echo "Input the new student information:" echo "学号 姓名 年龄 性别 电话" read ID name age sex phone if [ grep -w "$id" stu.db ] then echo "Students already exists!" echo "Please Reinput:" do_add else echo "$ID $name $age $sex $phone" >>stu.db echo "add success!" fi } do_delete() { echo "Input The ID to be deleted:" read ID if grep -w "$ID" stu.db then sed -i "/^$ID/d" stu.db echo "Delete success!" else echo "The student does not exist!" echo "Please Reinput:" do_delete fi } do_exit() { echo "exit OK!" exit 0 } do_Menu() { colour red_yellow while true do echo "1.输出学生信息" echo "2.查询学生信息(按学号或名字)" echo "3.修改学生信息" echo "4.添加学生信息" echo "5.删除学生信息(按学号)" echo "6.退出系统" echo "Input a correct number:" read key case $key in 1)do_print;; 2)do_inquire;; 3)do_update;; 4)do_add;; 5)do_delete;; 6)do_exit;; esac done } do_entry
#! /bin/bash colour () { #格式为背景:前景m,主要实现屏幕颜色显示 case $1 in black_white ) #背景为黑色,前景为白色 echo -e "\033[40;37m" ;; black_green ) #背景为黑色,前景为绿色 echo -e "\033[40;32m" ;; black_cyan ) #背景为黑色,前景为青色 echo -e "\033[40;36m" ;; red_yellow ) #背景为红色,前景为黄色 echo -e "\033[41;33m" ;; yellow_blue ) #背景为黄色,前景为蓝色 echo -e "\033[43;34m" ;; esac } do_register() { echo "Input ID:" read ID if grep "$ID" users.db then echo "User is already exists! please Input other username:" do_register fi echo "Input Password:" read PSW echo "Reinput Password:" read PSWt if [ $PSW -eq $PSWt ] then echo "$ID2 $PSW"21 >>users.db echo "create success!" else echo "Two passwords are not the same!" echo "Register failed!" fi } do_login() { echo "ID PSW:" read ID read PSW if grep "$ID $PSW" users.db then do_Menu else echo "login error!" fi } do_entry() { echo "***************************************" echo "********欢迎使用学生管理系统*********" echo "****** 1.创建用户 2.登录用户 ******" echo "****** (请输入选择序号) *******" echo "***************************************" echo -e "---->您的选择:\c" read val case $val in 1)do_register;; 2)do_login;; esac } do_print() { echo "学号 姓名 年龄 性别 电话" cat stu.db } do_inquire() { colour black_white echo "Input ID or name:" read x if grep -w "$x" stu.db then echo "学号 姓名 年龄 性别 电话" else echo "The student does not exist!" fi } do_update() { colour black_cyan echo "Input The Student's ID:" read ID if grep -w "$ID" stu.db then echo "Input the updated information:" echo "学号 姓名 年龄 性别 电话" read ID name age sex phone echo "$ID $name $age $sex $phone" >>stu.db echo "Update completed!" else echo "The student does not exist!" fi } do_add() { echo "Input the new student information:" echo "学号 姓名 年龄 性别 电话" read ID name age sex phone if [ grep -w "$id" stu.db ] then echo "Students already exists!" echo "Please Reinput:" do_add else echo "$ID $name $age $sex $phone" >>stu.db echo "add success!" fi } do_delete() { echo "Input The ID to be deleted:" read ID if grep -w "$ID" stu.db then sed -i "/^$ID/d" stu.db echo "Delete success!" else echo "The student does not exist!" echo "Please Reinput:" do_delete fi } do_exit() { echo "exit OK!" exit 0 } do_Menu() { colour red_yellow while true do echo "1.输出学生信息" echo "2.查询学生信息(按学号或名字)" echo "3.修改学生信息" echo "4.添加学生信息" echo "5.删除学生信息(按学号)" echo "6.退出系统" echo "Input a correct number:" read key case $key in 1)do_print;; 2)do_inquire;; 3)do_update;; 4)do_add;; 5)do_delete;; 6)do_exit;; esac done } do_entry