Home > Operation and Maintenance > Linux Operation and Maintenance > How shell implements student performance management system

How shell implements student performance management system

小云云
Release: 2018-05-10 13:54:55
Original
4041 people have browsed it

This article mainly introduces the student performance management system implemented by shell in detail. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.

Basic operations

Add
Delete
Query
Display all student information
vim edit the file that saves the information

Problems encountered

1. When adding student information

Add students When sending information, I use echo to redirect to the file. The one used here is >, which will cause overwriting. The previous data is gone.

Summary: Redirection symbols:

>: Overwriting writing method (the original content in the file is overwritten)

echo "hello world" > myfile
Copy after login

>>: Adding writing method (new The content is added after the original content)

echo "hello world" >> myfile
Copy after login

2. Delete a certain line of student information

I didn’t know how to delete it at first, but finally Found the grep -v command.
It means reverse selection, that is, displaying the line without the content of 'search string'.

Specific implementation code

#! /bin/bash

#查询函数
search()
{
    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 didnt eter a name to search";
        sleep 2;
        search;;
    esac
}

#增加信息
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
}

#删除学生信息
delete()
{
    clear 
    echo -e "Please enter delete name"
    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
}

#显示所有的记录函数
display()
{
    more ./record
}

#利用vim编辑器编辑函数
edit()
{
  vim ./record
}

#屏幕帮助操作
help()
{
  clear
  echo "this is a student record program by unix shell language!"
}

#推出程序
quit()
{
  clear
  exit
}

clear
while true
do
    echo "*********************************************"
    echo "****     student record menu    ****"
    echo "*********************************************"
    echo "---------------------------------------------"
    echo "#############################################"
    echo "       1-search a record       "
    echo "       2-add a record         "
    echo "       3-delete a record       "
    echo "       4-dispaly all records     "
    echo "       5-edit record with vim     "
    echo "       H-help             "
    echo "       Q-exit             "
    echo "#############################################"
    echo -e -n "Please enter your choice [1,2,3,4,5,6,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 "Invailid choice!";
    sleep 2;
    clear;;
    esac
  done
Copy after login

Related recommendations:

Student performance management system

Laravel5 student performance management system-07-add sidebar

Detailed explanation of the example of Linux shell implementation of library management system

The above is the detailed content of How shell implements student performance management system. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template