shell脚本:简单的分数记录系统
2016-09-26 18:07
225 查看
直接上代码:#mcore.sh
#!bin/bash
function colour()
{
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
}
function search()
{
colour black_white
clear
echo -e "please enter name >>>\c"
read NAME
if [ ! -f ./record ]; then
echo "you must have some scores before you can search"
sleep 2
clear
return
fi
if [ -z "$NAME" ]; then
echo "you didn t enter a name!"
echo -e "please enter name >>>\c"
read NAME
fi
grep -i "$NAME" ./record 2> /dev/null
case "$?" in
1) echo "Name not in record"
;;
2) echo "you didin t enter a name to search"
search;;
esac
}
function add()
{
clear
echo "enter name and score of a record"
echo -e "\c"
if [ ! -f ./record ];then
touch record
fi
read NEWNAME
echo "$NEWNAME" >./record
sort -o ./record ./record
}
function delete()
{
clear
echo -m "please enter name >>\c"
read NAME
if [ ! -f ./record ];then
echo "this name is not in record"
else
cp record record.bak
rm -f record
grep -v "$NAME" ./record.bak > record
rm -f record.bak
fi
}
function display()
{
colour black_white
more ./record
}
function edit()
{
vi ./record
}
function help()
{
clear
colour black_cyan
echo "this is a student s record program by lunix shell language"
}
function quit()
{
clear
colour black_white
exit
}
clear
while true
do
colour red_yellow
echo "****************************************"
echo "*STUDENT S RECORD MENU *"
echo "****************************************"
colour yellow_blue
echo "****************************************"
echo "*1:search a record *"
echo "*2:add a record *"
echo "*3:delete a recore *"
echo "*4:dispaly all records *"
echo "*5:edit record witm vi *"
echo "*H:help screen *"
echo "*Q:exit program *"
echo "****************************************"
colour black_green
echo -e -n "\tplease enter you choice 1--5,H,Q:\c"
read CHOICE
case $CHOICE in
1) search;;
2) add; clear;;
3) delete; clear;;
4) display;;
5) edit; clear;;
H | h) help;;
Q | q) quit;;
*) echo "invalid choice";
sleep 2;
clear;;
esac
done运行结果:
本文出自 “剩蛋君” 博客,请务必保留此出处http://memory73.blog.51cto.com/10530560/1791539
#!bin/bash
function colour()
{
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
}
function search()
{
colour black_white
clear
echo -e "please enter name >>>\c"
read NAME
if [ ! -f ./record ]; then
echo "you must have some scores before you can search"
sleep 2
clear
return
fi
if [ -z "$NAME" ]; then
echo "you didn t enter a name!"
echo -e "please enter name >>>\c"
read NAME
fi
grep -i "$NAME" ./record 2> /dev/null
case "$?" in
1) echo "Name not in record"
;;
2) echo "you didin t enter a name to search"
search;;
esac
}
function add()
{
clear
echo "enter name and score of a record"
echo -e "\c"
if [ ! -f ./record ];then
touch record
fi
read NEWNAME
echo "$NEWNAME" >./record
sort -o ./record ./record
}
function delete()
{
clear
echo -m "please enter name >>\c"
read NAME
if [ ! -f ./record ];then
echo "this name is not in record"
else
cp record record.bak
rm -f record
grep -v "$NAME" ./record.bak > record
rm -f record.bak
fi
}
function display()
{
colour black_white
more ./record
}
function edit()
{
vi ./record
}
function help()
{
clear
colour black_cyan
echo "this is a student s record program by lunix shell language"
}
function quit()
{
clear
colour black_white
exit
}
clear
while true
do
colour red_yellow
echo "****************************************"
echo "*STUDENT S RECORD MENU *"
echo "****************************************"
colour yellow_blue
echo "****************************************"
echo "*1:search a record *"
echo "*2:add a record *"
echo "*3:delete a recore *"
echo "*4:dispaly all records *"
echo "*5:edit record witm vi *"
echo "*H:help screen *"
echo "*Q:exit program *"
echo "****************************************"
colour black_green
echo -e -n "\tplease enter you choice 1--5,H,Q:\c"
read CHOICE
case $CHOICE in
1) search;;
2) add; clear;;
3) delete; clear;;
4) display;;
5) edit; clear;;
H | h) help;;
Q | q) quit;;
*) echo "invalid choice";
sleep 2;
clear;;
esac
done运行结果:
本文出自 “剩蛋君” 博客,请务必保留此出处http://memory73.blog.51cto.com/10530560/1791539
相关文章推荐
- shell脚本:简单的分数记录系统
- shell script自动搭建简单的linux系统初始化脚本
- 分布式监控系统Zabbix-3.0.3-完整安装记录 - 添加shell脚本监控
- centos系统故障-Centos简单处理CC攻击shell脚本
- 【sehll学习】linux运维一个简单shell脚本监控系统内存
- 巨简单循环shell脚本验证&符号后台操作(并记录查看当前shell的方法)
- 初学shell,为了练习sed,写了个简单的批量修改文件名的脚本,后来执行时发现系统竟然自带有一个rename命令,顺便也记下了
- shell脚本02--记录系统资源消耗
- 简单shell脚本记录(整理中)
- 第一个shell脚本用到的一些简单命令,记录下
- shell 脚本之“比较” 以及简单截取
- Linux系统中的Shell脚本调试技术
- 计算linux系统资源的简单脚本
- Linux系统日志记录到远程服务器简单配置
- 使用shell脚本进行服务器系统监控——页面调度与交换空间监控
- shell脚本监控系统负载,并在负载过大时发送邮件报警
- 比较简单windows系统不用RMAN的oracle数据库冷备脚本
- 比较简单windows系统不用RMAN的oracle数据库热备脚本
- 【转】Linux系统中的Shell脚本调试技术
- 使用shell脚本进行服务器系统监控——系统负载监控(1)