欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

shell實(shí)現(xiàn)圖書(shū)管理系統(tǒng)

 更新時(shí)間:2018年01月18日 15:16:54   投稿:lijiao  
這篇文章主要介紹了shell實(shí)現(xiàn)圖書(shū)管理系統(tǒng),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了shell實(shí)現(xiàn)圖書(shū)管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

#!/bin/bash 
#author:zhanghongjun 
#version:1.0 
#date:2011年 12月 14日 星期三 21:18:18 CST 
 
 
function information 
{ 
  echo "---------------------------" 
  echo "圖書(shū)館管理系統(tǒng)(5.4版本)" 
  echo  
  echo -n "| " ;echo "1:添加圖書(shū)" 
  echo -n "| " ;echo "2:刪除圖書(shū)" 
  echo -n "| " ;echo "3:圖書(shū)列表" 
  echo -n "| " ;echo "4:查找圖書(shū)" 
  echo -n "| " ;echo "5|q:退出系統(tǒng)" 
  echo  
  echo "---------------------------" 
  read -p "請(qǐng)輸入你的選擇:" a 
   
 
  case "$a" in 
  1) 
    add ;; 
  2) 
    delete ;; 
  3) 
    list ;; 
  4) 
    search;; 
  5|q|Q) 
    return -1 ;; 
  *) 
    information ;; 
  esac 
} 
 
 
function file_exist 
{ 
  if [ ! -f .book.txt ];then 
    touch .book.txt 
  fi 
} 
 
 
function add 
{ 
  read -p "請(qǐng)輸入圖書(shū)的編號(hào):" number 
  read -p "請(qǐng)輸入圖書(shū)的書(shū)名:" book_name 
  read -p "請(qǐng)輸入圖書(shū)的作者:" author 
  read -p "請(qǐng)輸入圖書(shū)的價(jià)格:" price  
    echo -e "$number\t$book_name\t$author\t$price" >>.book.txt && { 
      echo "添加圖書(shū)成功!" 
      echo "-------------------" 
    } 
  if [ $? -ne 0 ];then 
    echo "添加圖書(shū)失敗" 
  fi 
  information 
 
} 
 
function delete 
{ 
  read -p "請(qǐng)輸入要?jiǎng)h除的圖書(shū)的編號(hào):" number 
  grep $number .book.txt &>/dev/null && { 
      sed -i '/\<'$number'\>/d' .book.txt &>/dev/null && 
      echo "刪除圖書(shū)成功"  
  echo "-------------------------" 
  } 
   
  if [ $? -ne 0 ];then 
    echo "刪除圖書(shū)失敗" 
    echo "你要?jiǎng)h除的圖書(shū)不存在" 
  fi 
  information 
} 
 
#列出所有圖書(shū)的信息 
function list 
{ 
  echo -e "編號(hào)\t書(shū)名\t作者\(yùn)t價(jià)格" 
  cat .book.txt 
  echo "----------------------------" 
  information 
   
} 
 
 
#下面的函數(shù)用到的查詢(xún)菜單 
function search_menu 
{ 
  echo;echo "----------------------------"  
  echo -n "|";echo -e "1:\t按圖書(shū)編號(hào)查詢(xún)" 
  echo -n "|";echo -e "2:\t按圖書(shū)書(shū)名查詢(xún)" 
  echo -n "|";echo -e "3:\t按圖書(shū)作者查詢(xún)" 
  echo -n "|";echo -e "4:\t按圖書(shū)價(jià)格查詢(xún)" 
  echo -n "|";echo -e "5|q:\t退出查詢(xún)系統(tǒng)" 
  echo;echo "----------------------------"  
 
} 
function search 
{ 
  search_menu 
  read -p "請(qǐng)輸出你的選擇:" myselect 
  case "$myselect" in 
  1) 
    read -p "請(qǐng)輸入要查詢(xún)的圖書(shū)的編號(hào):" mynumber 
    echo -e "編號(hào)\t書(shū)名\t作者\(yùn)t價(jià)格\n" 
    awk '$1=='$mynumber'{print $0}' .book.txt 2>/dev/null  
               
    if [ $? -ne 0 ];then 
      echo "圖書(shū)不存在" 
    fi 
    search 
    ;; 
  2) 
    read -p "請(qǐng)輸入你要查詢(xún)的書(shū)名:" mybook_name 
    echo -e "編號(hào)\t書(shū)名\t作者\(yùn)t價(jià)格\n" 
    awk '$2~/'$mybook_name'/{print $0}' .book.txt 2>/dev/null 
    if [ $? -ne 0 ];then 
      echo "圖書(shū)不存在" 
    fi 
    search 
    ;; 
  3) 
    read -p "請(qǐng)輸入圖書(shū)的作者:" myauthor 
    echo -e "編號(hào)\t書(shū)名\t作者\(yùn)t價(jià)格\n" 
    awk '$3~/'$myauthor'/{;print $0}' .book.txt 2>/dev/null 
    if [ $? -ne 0 ];then 
      echo "圖書(shū)不存在" 
    fi 
    search 
    ;; 
  4) 
    read -p "請(qǐng)輸入圖書(shū)的價(jià)格:" myprice 
    echo -e "編號(hào)\t書(shū)名\t作者\(yùn)t價(jià)格\n" 
    awk '$4=='$myprice'{print $0}' .book.txt 2>/dev/null 
    if [ $? -ne 0 ];then 
      echo "圖書(shū)不存在" 
    fi 
    search 
    ;; 
  5) 
    information 
    ;; 
  *) 
    information 
    ;; 
  esac 
 
} 
 
information 

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論