shell编程图书管理系统源码.docx
- 文档编号:25318918
- 上传时间:2023-06-07
- 格式:DOCX
- 页数:11
- 大小:15.57KB
shell编程图书管理系统源码.docx
《shell编程图书管理系统源码.docx》由会员分享,可在线阅读,更多相关《shell编程图书管理系统源码.docx(11页珍藏版)》请在冰豆网上搜索。
shell编程图书管理系统源码
先新建一个文件命名为lib.db,用记事本打开,粘贴以下:
TitleAuthorCategoryStateBnameDate
=======================================================================
test7authortextbookinnonenone
test2author2referenceoutxiong2015/6/14
test1authorsystemoutjie2015/6/10
test4author4textbookinnonenone
test5author5referenceoutqun2015/6/10
test3author3systeminnonenone
test6author6textbookoutlin2015/6/10
test8authorsysteminnonenone
test9author9textbookinnonenone
接下来是源码,源码文件要和lib.db文件放在同一目录下
#!
/bin/sh
#################################################
#Function:
menu#
#################################################
menu()
{
echo"\t\t\t################################"
echo"\t\t\t##"
echo"\t\t\t#1.Addbook#"
echo"\t\t\t#2.Deletebook#"
echo"\t\t\t#3.Searchbook#"
echo"\t\t\t#4.Showallbook#"
echo"\t\t\t#5.Borrowbook#"
echo"\t\t\t#6.Returnbook#"
echo"\t\t\t#7.Exit#"
echo"\t\t\t##"
echo"\t\t\t################################"
echo"\t\t\t\tSelect:
\c"
}
#################################################
#Function:
Addbook#
#################################################
Addbook()
{
echo"Pleaseinputtheinformation!
\n"
echo"Book'stitle:
\c"
readtitle
info=`grep-w$titlelib.db`
if[!
-z"$info"];then
clear
echo"\n\nThisbookalreadyexists!
\n\n"
else
echo"Author:
\c"
readauthor
echo"Category(reference/system/textbook):
\c"
readcategory
echo"$title$author$categoryinnonenone">>lib.db
clear
echo"\n\nAddbooksuccessfully!
\n\n"
fi
echo"inputentertoexit!
\n\n\n"
echo"Anymorebooktoadd(y/n)?
\c"
readyn
y="y";n="n"
if["$yn"="$y"];then
clear
echo"\n\n\n"
Addbook;
else
clear
return
fi
}
#################################################
#Function:
Deletebook#
#################################################
Deletebook()
{
echo"Pleaseinputthebook'stitleyourwanttodelete!
\n"
echo"Book'stitle:
\c"
readtitle
info=`grep-w$titlelib.db`
clear
if[!
-z"$info"];then
awk'BEGIN{printf"%-8s%-10s%-12s%-8s%-10s%-12s\n",\
"Title","Author","Category","State","Bname","Date"}'
echo"==================================================================\n"
awk'$1=="'$title'"{printf"%-8s%-10s%-12s%-8s%-10s%-12s\n",\
$1,$2,$3,$4,$5,$6}'lib.db
echo"\n\nAreyousuretodelete\"$title\"(y/n)?
\c"
y='y';n='n'
readyn
clear
if["$yn"="$y"];then
sed-i-e'/'"$title"'/d'lib.db|>>lib.db
echo"\n\nDeletethebooksuccessfully!
\n\n"
elif["$yn"="$n"];then
echo"\n\nDeletefailed!
\n\n"
fi
else
echo"\n\nNosuchbook!
\n\n"
fi
echo"inputentertoexit!
\n\n"
echo"Anymorebooktodelete(y/n)?
\c"
readyn
y="y";n="n"
if["$yn"="$y"];then
clear
echo"\n\n\n"
Deletebook;
else
clear
return
fi
}
#################################################
#function:
Search#
#################################################
Searchbook()
{
echo"Pleaseinputthebook'stitleyouwanttosearch!
\n"
echo"Book'stitle:
\c"
readtitle
info=`grep-w$titlelib.db`
clear
if[!
-z"$info"];then
#sed-i-e'/'"$title"'/d'lib.db
#echo"\n\nDeletethebooksuccessfully!
\n\n\n"
awk'BEGIN{printf"%-8s%-10s%-12s%-8s%-10s%-12s\n",\
"Title","Author","Category","State","Bname","Date"}'
echo"==================================================================\n"
awk'$1=="'$title'"{printf"%-8s%-10s%-12s%-8s%-10s%-12s\n",\
$1,$2,$3,$4,$5,$6}'lib.db
else
echo"\n\nNosuchbook!
"
fi
#echo"\n\ninputentertoexit!
\c"
#readtmp
#clear
echo"\n\nAnymorebooktosearch(y/n)?
\c"
readyn
y="y";n="n"
if["$yn"="$y"];then
clear
echo"\n\n\n"
Searchbook;
else
clear
return
fi
}
#################################################
#function:
Showall#
#################################################
Showall()
{
clear
awk'{printf"%-8s%-10s%-12s%-8s%-10s%-12s\n",$1,$2,$3,$4,$5,$6}'lib.db
echo"\ninputentertoexit!
\c"
readtmp
clear
}
#################################################
#function:
Borrowbook#
#################################################
Borrowbook()
{
echo"Pleaseinputthebook'stitleyouwanttoborrow!
\n"
echo"Book'stitle:
\c"
readtitle
info=`grep-w$titlelib.db`
if[-z"$info"];then
clear
echo"\n\nNosuchbook!
\n\n"
echo"inputentertoexit!
\c"
readtmp
clear
return
fi
state=`awk'$1=="'$title'"{print$3}'lib.db`
clear
tmp='out'
if["$state"="$tmp"];then
echo"\n\nThisbookhavebeenborrowed!
\n\n"
else
state="out"
title=`awk'$1=="'$title'"{print$1}'lib.db`
author=`awk'$1=="'$title'"{print$2}'lib.db`
category=`awk'$1=="'$title'"{print$3}'lib.db`
echo"Inputborrower'sname:
\c"
readbname
echo"Inputthedaytime(year/month/day):
\c"
readdate
sed-i-e'/'"$title"'/d'lib.db|>>lib.db
echo"$title$author$category$state$bname$date">>lib.db
clear
echo"\n\nBorrowbooksuccessfully!
\n\n"
fi
#echo"inputentertoexit!
\c"
#readtmp
#clear
echo"\n\nAnymorebooktoborrow(y/n)?
\c"
readyn
y="y";n="n"
if["$yn"="$y"];then
clear
echo"\n\n\n"
Borrowbook;
else
clear
return
fi
}
#################################################
#function:
Returnbook#
#################################################
Returnbook()
{
echo"Pleaseinputthebook'stitleyouwanttoreturn!
\n"
echo"Book'stitle:
\c"
readtitle
clear
info=`grep-w$titlelib.db`
if[-z"$info"];then
echo"\n\nNosuchbook!
\n\n"
echo"inputentertoexit!
\c"
readtmp
clear
return
fi
awk'BEGIN{printf"%-8s%-10s%-12s%-8s%-10s%-12s\n",\
"Title","Author","Category","State","Bname","Date"}'
echo"==========================================================================\n"
awk'$1=="'$title'"{printf"%-8s%-10s%-12s%-8s%-10s%-12s\n",\
$1,$2,$3,$4,$5,$6}'lib.db
echo"\n\nAreyousuretoreturn\"$title\"(y/n)?
\c"
y='y';n='n'
readyn
clear
if["$yn"="$y"];then
state="in"
author=`awk'$1=="'$title'"{print$2}'lib.db`
category=`awk'$1=="'$title'"{print$3}'lib.db`
bname=none
date=none
sed-i-e'/'"$title"'/d'lib.db|>>lib.db
echo"$title$author$category$state$bname$date">>lib.db
echo"\n\nThebookhasbeenreturn!
\n\n"
elif["$yn"="$n"];then
echo"\n\nReturnfailed!
\n\n"
fi
#echo"inputentertoexit!
\c"
#readtmp
#clear
echo"\n\nAnymorebooktoreturn(y/n)?
\c"
readyn
y="y";n="n"
if["$yn"="$y"];then
clear
echo"\n\n\n"
Returnbook;
else
clear
return
fi
}
clear
menu
while(testtrue)
do
readchoice
case$choicein
1)Addbook;;
2)Deletebook;;
3)Searchbook;;
4)Showall;;
5)Borrowbook;;
6)Returnbook;;
7)exit;;
*)clear;echo"\n\nWrongChoice!
\n\n\n"
esac
menu
done
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- shell 编程 图书 管理 系统 源码