Shell实现模拟数据库操作

#!/bin/bash
#auto=ddy
#vsion=1.0
####打印出菜单
begin_echo(){
echo -e "\033[41;33m
###################################
#       1.search a record         #
#       2.add a record            #
#       3.delete a record         #
#       4.display all record      #
#       5.edit record with vi     #
#       H:help sreen              #
#       Q:exit pragma             #
###################################
\033[0m"
read -p "`echo -e "\033[40;32mplease enter your choice [1 2 3 4 5 H Q]:\033[0m"`" number
}

####判断处理
panduan(){
case number in         1)         number_1         ;;         2)         number_2         ;;         3)         number_3         ;;         number_4         ;;         5)         number_5         ;;         h|H)         help_list         ;;         q|Q)         quit         ;;         *)         echo "不在范围内!"         ;; esac }  ####当判断为1时  number_1(){ clear while : do read -p "please enter name >>>" input a=`cat /record|grep "input"`
        if [ -f /record ];then
          if [ -z input ];then             echo -e "\033[41;33myou  didn't  enter  a  name!\033[0m"             sleep 3             continue           fi           if [ -z a ];then
            echo -e "\033[41;33mname  not  in record\033[0m"
            sleep 1
            break
        else
            echo "###查询的内容###"
            echo "a"             echo "################"             sleep 3             break           fi         else           if [ -z input ];then
            echo -e "\033[41;33myou  didn't  enter  a  name!\033[0m"
            continue
          else
            echo -e "\033[41;33myou  must  have  some  scores  before  you  can  search!!!\033[0m"
            continue
          fi
        fi
done
}

#####判断为2时候
number_2(){
clear
read -p "`echo -e "\033[40;32menter name  and score  of  a  recoed >>>:\033[0m"`" addcommon
while :
do
        if [ -z addcommon ];then           echo "you  didn't  enter  any  value"           read -p "please  enter  name  and  score:" addcommon continue         else           b=[`cat /record |cut -d . -f 1|tail -1`+1]
          c=[RANDOM%100]
          echo "b.addcommon.c">>/record           echo "added  addcommon in record"
          sleep 3
          break
        fi
done
}

#####当判断为3时候
number_3(){
clear
read -p "please you want to delete (name/line):" name
sed -i "/name/d" /record awk -F . '{print NR"."2"."$3}' /record >/re
mv /re /record
}

#####当判断为4时候
number_4(){
cat /record
sleep 3
}

#####当判断为5时候

number_5(){
vim /record
}

#####当判断为h时候

help_list(){

clear
echo "This is a student's record manager program!"
sleep 3
}

#####当判断为exit

quit(){
exit 0
}

#####主函数
while :
do
clear
begin_echo
panduan
done

Shell实现模拟数据库操作》有2个想法

  1. You could definitely see your skills within the paintings you write. The world hopes for even more passionate writers like you who are not afraid to mention how they believe. At all times follow your heart. “He never is alone that is accompanied with noble thoughts.” by Fletcher.

发表评论