|
文件: |
operdatafile.rar |
大小: |
1KB |
下载: |
下载 | |
两个文件:
1,mainprog.sh
#datafile=$HOME/bourne/datafile
datafile=./datafile
. dbfunctions
if [ ! -f $datafile ] then echo "`basename $datafile` does not exist" 1>&2 touch ./datafile fi while true do echo "Select one: " cat <<EOF [1] Add info [2] Delete info [3] Update info [4] View info [5] Exit EOF read choice case $choice in 1) addon ;; 2) delete ;; 3) update ;; 4) list ;; 5) echo Bye exit 0 ;; *) echo Bad choice
;; esac #echo Returned from function call
done
|
2,dbfunctions
addon () { while true do echo "Adding information " echo "Type the full name of employee " read name echo "Type address for employee " read address echo "Type start date for employee (4/10/88 ) :" read startdate echo $name:$address:$startdate echo -n "Is this correct? " read ans case "$ans" in [Yy]*) echo "Adding info..." echo $name:$address:$startdate>>$datafile sort -u $datafile -o $datafile echo -n "Do you want to go back to the main menu? " read ans if [ $ans == Y -o $ans == y ] then return else continue fi ;; *) echo "Do you want to try again? " read answer case "$answer" in [Yy]*) continue;; *) exit;; esac ;; esac done } delete () {
while true do echo "delete information" echo "type the full name of employee who will be deleted" read name echo "searching......." findname=`cat $datafile | grep "^$name:"` if [ "$findname" == "" ] ; then echo "not found" echo -e "not found\n do you want to try again?" read yn if [ $yn == Y -o $yn == y ]; then continue else return fi else echo -e "do you want delete this name?" read yn if [ $yn == Y -o $yn == y ] then sed -i "/^$name:/d" $datafile echo "have deleted" return else continue fi fi done } update () {
while true do echo "update information" echo "type the full name of employee who will be updated" read name echo "searching......." findname=`cat $datafile | grep "^$name:"` if [ "$findname" == "" ] ; then echo "not found" echo -e "not found\n do you want to try again?" read yn if [ $yn == Y -o $yn == y ]; then continue else return fi else echo -e "do you want update this name?" read yn if [ $yn == Y -o $yn == y ] then echo "Type the full name of employee " read name_new echo "Type address for employee " read address_new echo "Type start date for employee (4/10/88 ) :" read startdate_new sed -i "s/^$name:.*$/$name_new:$address_new:$startdate_new/g" $datafile sort -u $datafile -o $datafile echo "have update" return else continue fi fi done } list () { while true do echo "list information" echo "tyoe the full name of employee who will be listed (type all to list all employee):" read name if [ $name == "all" ]; then echo "************************" cat $datafile echo "************************" return fi echo "searching......." findname=`cat $datafile | grep "^$name:"` if [ "$findname" == "" ] ; then echo "not found" return else echo "************************" echo $findname echo "************************" return fi
done }
|
文件也传一份吧,可以下载,方便一些。这样的程序我以前用c写过一个,有空我也发过来吧。
阅读(1008) | 评论(0) | 转发(0) |