#!/usr/bash
#Output file save the students information
FILE=./student.db
#temp file
TMP=./.tmp
#This is menu
menu () {
echo "************************************************"
echo -e "\t1.Add a student information"
echo -e "\t2.Query a student information"
echo -e "\t3.Delete a student information by ID"
echo -e "\t4.Screen clearing"
echo -e "\t0.Exit this program"
echo "************************************************"
echo -n "Select:"
}
#Add a student infomation
add () {
#validate ID
while [ 1 ];do
echo -n "Student ID(001-999):"
read id
flag=`echo $id|grep -c "^[0-9]\{3\}$"`
if [ $flag -eq 0 -o "$id" == "000" ] ; then
echo "ID must 001-999"
continue
fi
flag2=`awk '{print $1}' $FILE | grep -c ^${id}$`
if [ $flag2 -ge 1 ] ;then
echo "ID:${id} is already exists!"
continue
fi
break
done
#validate Name
while [ 1 ];do
echo -n "Student name(only a-z,A-Z and within 5 characters):"
read name
#flag record match line number
flag=`echo $name | grep -c "^[a-zA-Z]\{1,5\}$"`
if [ $flag -eq 0 ] ; then
echo "Name must within 5 characters only a-z,A-Z"
continue
else
#Name into the capital letters
name=`echo $name | tr '[a-z]' '[A-Z]'`
break
fi
done
#validate Sex
echo -n "Student sex(M or F,default is M):"
read sex
if [ "$sex" = "F" -o "$sex" = "f" ] ; then
sex=F
else
sex=M
fi
#validate Class
while [ 1 ]; do
echo -n "Student class(01-99 default is NULL):"
read class
if [ "$class" == "" ];then
class=NULL
break
fi
#Class match 00-99
flag=`echo $class|grep -c "^[0-9]\{2\}$"`
#check ?
if [ $flag -eq 0 -o "$class" == "00" ] ; then
echo "class must 01-99"
else
break
fi
done
echo -e "$id\t$name\t$sex\t$class" >> $FILE
echo "Add student information success"
}
queryById () {
echo -n "Student ID:"
read id
if [ "$id" == "" ];then
queryAll
return
fi
echo -e "ID\tName\tSex\tClass"
grep $id $FILE
if [ $? != 0 ]; then
echo "No student information!"
fi
}
queryByKeyword () {
echo -n "Keyword:"
read key
if [ "$key" == "" ]; then
queryAll
return
fi
echo -e "ID\tName\tSex\tClass"
grep -i $key $FILE
if [ $? != 0 ]; then
echo "Can't find the matching items"
fi
}
queryAll () {
echo -e "ID\tName\tSex\tClass"
grep "" $FILE
if [ $? != 0 ]; then
echo "No records found"
fi
}
query () {
echo "1.Through the student ID to queries"
echo "2.Througt the Keyword to queries"
echo "3.Query all students information"
echo -n "Select:"
read option
case $option in
1) queryById ;;
2) queryByKeyword ;;
3) queryAll ;;
*) queryAll ;;
esac
}
#Delete student
delete () {
echo "1.Delete by ID"
echo "2.Delete containt ID"
echo -n "Select:"
read opt
case $opt in
1) deleteById ;;
2) deleteMatchId ;;
*) error ;;
esac
}
#Delete student by ID
deleteById () {
flag=`grep -n "$id" $FILE`
if [ "$flag" == "" -o "$id" == "" ]; then
echo "can't find ID=$id student"
return
fi
#get delete number
num=`awk '{print $1}' $FILE | grep -n "${id}" |sed 's/:.*//g'`
echo -e "ID\tName\tSex\tClass"
#print the delete number
sed -n "${num}p" $FILE
echo -n "Are you sure delete id(Y or N):"
read sure
if [ "$sure" == "Y" -o "$sure" == "y" ] ; then
sed "${num}d" $FILE > $TMP
cat $TMP > $FILE
echo "Deleted successful"
fi
}
#Delete student macth ID
deleteMatchId () {
echo -n "Input the student ID:"
read id
echo -e "ID\tName\tSex\tClass"
#The first domain macth ID
awk -F"\t" '$1~ /'$id'/ {print $0}' $FILE
echo -n "Delete all ?(Y or N):"
read all
if [ "$all" == "Y" -o "$all" == "y" ] ; then
#get match number
#num=`grep -n "" $FILE | awk '$1~/'$id'/' | sed 's/:.*//g'`
#num=`awk '$1~ /'$id'/ {print $0}' $FILE | grep -n "" |sed 's/:.*//g'`
#sed "${num}d" $FILE > $TMP
awk '$1!~/'$id'/ {print $0}' $FILE >$TMP
cat $TMP > $FILE
echo "Deleted successful"
fi
return
}
#exit program
quit () {
cls
echo "Thank you Bye!"
exit
}
#Error info
error () {
echo "Error input!"
}
#screen cleaning
cls () {
clear
}
#read anykey
anykey () {
echo -n "press Enter key to continue..."
read anykey
cls
}
#main
main () {
touch $FILE
while [ 1 ] ; do
menu
read number
case $number in
1) add ; anykey ;;
2) query ; anykey ;;
3) delete ; anykey ;;
4) cls ;;
0) quit ;;
*) error ;;
esac
done
}
main
分享到:
相关推荐
linux 程序设计 实验 shell 编程 学生成绩管理系统
shell系统,适合初学者,代码很差劲。第一次写shell
基于shell和mysql的学生成绩管理系统
图书管理系统,linux环境下shell编程,shell命令
这是个实验的题目,在这次的unix实验中就只有这个比较难一点,感觉写shell更多的是要求一个的逻辑思维能力而不是什么算法....之类的。
shell脚本下的简易的图书馆管理系统。 适合课程设计 和 初次学习的 兄弟们。
js-shell-0.2.zip,很明白了。不用多说了。就是让js的逻辑地位提高些。像写java一样写js。
Linux初学者理解shell编程,入门小项目
主要为大家详细介绍了shell编程实现学生成绩管理系统,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
VS中自带的旧版本的V1.0兼容性差,问题多多。Shell32.dll V1.2.107 用于替换VS中自带的旧版本的V1.0
HS8145V补全shell的bin文件,工具包。
用shell script 编写的学生成绩管理系统,实现了增删改查,可改写和完善
本文实例为大家分享了shell实现学生成绩管理系统的具体代码,供大家参考,具体内容如下 基本的操作 增加 删除 查询 展示全部学生信息 vim编辑保存信息的文件 遇到的问题 1.增加学生信息时 增加学生信息时,我用的...
简单的shell脚本下的系统。 比较简单,有登陆界面,usersystem和managersystem。
这个补丁可以补全shell。需要web界面打开LAN侧的telnet,打开tftp服务器,然后登陆telnet,在WAP提示符load pack by tftp svrip 192.168.1.2 remotefile hs8546v_shell_spbin。更具体步骤在此不做说明。
实验三 学生成绩管理程序(Shell程序设计) 实验内容 作业:学生成绩管理程序 功能: 对学生成绩进行管理。要求实现数据的基本操作:学院和学生信息以及学生成绩的增加,修改,删除,统计 构造三个类似数据库的文本...
nterop.Shell32.dll vs自带的是1.0 会导致一些错误,这个是1.2的
双击应用程序就能查询全国大部分城市未来3天的天气情况。(包括气温,湿度,风向,风力。。。等各种详细信息) 使用简便,点击即可查询 colin3dmax原创
华为光猫HS8546V SHELL补全工具,可以进控制台改双模.