学生成绩管理系统shell

echo “$name" > 文件名 文件的里原来的内容被覆盖

echo “helloworld” >> 文件名 新内容添加在原来的内容后

grep 关键字 文件名 搜索文件中有关键字的行 -i 无关大小写

-v 反向搜索 搜索不含关键字的行 可用来删除某一行信息

#!/bin/bash
#filename:studentscore


search()
{
    clear

    if [ ! -f student.txt ];then
	echo have no record
	sleep 2
        return
    fi

    echo input your name:
    read name

    if [ -z $name ];then
	echo you didnt input a name
	echo input your name:
	read name
    fi

    grep -i $name student.txt

    case $? in
	1)echo name not in record 
	    ;;
	0)echo search success 
	    ;;
esac

    sleep 2

}

add()
{
    clear

    if [ ! -f student.txt ];then
	touch student.txt
    fi

    echo please add name and score:
    read newname

    echo $newname >> student.txt

    sort -o student.txt student.txt
    echo " add success "

    sleep 2

}

delete()
{
    clear

    if [ ! -f student.txt ];then
	echo no record can delete
	sleep 2
	return
    fi

    echo please input delete name:
    read name

    grep -i $name student.txt

    case $? in
	1)echo name not in record
	    ;;
	0)cp student.txt student1.txt
	    rm -f student.txt
	    grep -v "$name" student1.txt > student.txt
	    rm -f student1.txt
	    echo delete success
	    ;;
    esac

    sleep 2

}

display()
{
    clear

    more student.txt

    sleep 4

}

edit()
{
    vim student.txt

}

c()
{
    clear
}

quit()
{
    clear

    echo -e    "\033[45;37m"

    exit
}

echo -e    "\033[30;32m"

while true
do
    clear
    echo "*****************************"
    echo "***  student score menu   ***"
    echo "*****************************"
    echo "#############################"
    echo "      1-search               "
    echo "      2-add                  "
    echo "      3-delete               "
    echo "      4-display all record   "
    echo "      5-edit                 "
    echo "      c-clear                "
    echo "      Q-quit                 "
    echo "#############################"
    echo -e -n "please input your choice [ 1,2,3,4,5,Q,c ] : "
    read choice

    case $choice in
	1)search
	    ;;
	2)add
	    ;;
	3)delete
	    ;;
	4)display
	    ;;
	5)edit
	    ;;
	c|C)c
	    ;;
	q|Q)quit
	    ;;
	*)echo error choice
	    sleep 2
	    clear
	    ;;
    esac
done

在这里插入图片描述在这里插入图片描述

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

家住隔壁我姓王8

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值