文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>一个简单通讯录shell

一个简单通讯录shell

时间:2006-08-18  来源:h0ng123


结构图:
                            |------- add
         |-------edit-------|    
main-----|                  |--------update  
         |                  |
         |                  |--------display
         |                  |
         |                  |---------delete
         |
         |
         |-------report ------report_no
         |
         |-------error
代码
#main
BOLD=`tput smso`
NORMAL=`tput rmso`
export  BOLD  NORMAL
tput clear
tput cup 5 15
echo "${BOLD}Supper duper unix library"
tput cup 12 10
echo "${NORMAL}This is  the unix library application"
tput cup 14 10;echo -e "Please enter any key to continue..._\b\c"
read answer
error_flag=0
while true
do
 if [ $error_flag -eq 0 ]
 then
   tput  clear
   tput cup 5 10
   echo "Unix library-${BOLD}Main menu${NORMAL}"
   tput cup 7 20; echo "0:${BOLD}exit${NORMAL}This program"
   tput cup 9 20; echo "1:${BOLD}Edit${NORMAL}Menu"
   tput cup 11 20;echo "2:${BOLD}Reports${NORMAL}menu"
  error_flag=0
 fi
tput cup 13 20 ;  echo -e "Enter your choice>_\b\c"
read choice
 case $choice in
   0) tput clear; exit 0;;
   1) sh edit;;
   2) sh report;;
   *) sh error cup 14 20
   tput cup 14 20 ; tput ed
   error_flag=1;;
 esac
done
exit 0
  #edit
error_flag=0
while true
do
 if [ $error_flag -eq 0 ]
 then
 tput clear; tput cup 5 10
 echo "Unix Library-${BOLD}edit menu${NORMAL}"
 tput cup 7 20
 echo "0:${BOLD}Return ${NORMAL}to the main menu"
 tput cup 9 20 ; echo "1:${BOLD}ADD${NORMAL}"
 tput cup 11 20; echo "2:${BOLD}UPDATE${NORMAL}"
 tput cup 13 20; echo "3:${BOLD}DISPLAY${NORMAL}"
 tput cup 15 20; echo "4:${BOLD}DELETE${NORMAL}"
 fi
error_flag=0
tput cup 17 10; echo -e "Enter your choice>_\b\c"
read choice
case $choice in
0) exit;;
1) sh add;;
2) sh update;;
3) sh display;;
4) sh delete;;
*) sh error 20 10
 tput cup 20 1;tput ed
error_flag=1;;
esac
done
exit 0

#report
 printf("you got a connect from %s\n",inet_ntoa(client.sin_addr));
error_flag=0
while true
do
  if  [ $error_flag -eq 0 ]
  then
   tput clear ; tput cup 5 10
   echo "UNIX Library - ${BOLD}REPORTSMENU{NORMAL}"
   tput cup 7 20
   echo "0:${BOLD}RETURN${NORMAL}"
   tput cup 9  20 ; echo "1:Sorted by ${BOLD}TITLES${NORMAL}"
   tput cup 11 20 ; echo "2:Sorted by ${BOLD}AUTHOR${NORMAL}"
   tput cup 13 20 ; echo "3:Sorted by ${BOLD}CATEGORY${NORMAL}"
  fi
error_flag=0
tput cup 17 10; echo -e "Enter your choice>_\b\c"
read choice
#
#case construct for checking the user selection
#
case $choice in
 0)exit 0 ;;
 1)sh report_no 1;;
 2)sh report_no 2;;
 3)sh report_no 3;;
 *)sh error 20 10
   tput cup 20 1 ;tput ed
   error_flag=1 ;;
esac
done
exit 0

#error
tput cup $1 $2
  printf("you got a connect from %s\n",inet_ntoa(client.sin_addr));
echo "Wrong Input.Try again."
echo  -e "Press ${BOLD}ENTER ${NORMAL}key to continue...>_\b\c"
read answer
exit 0

#add
answer=y
while [ "$answer" = y ]
do
tput clear
tput cup 5 10; echo "UNIX Library---${BOLD}ADD MODE"
echo "${NORMAL}"
tput cup 7 23; echo "Title:"
tput cup 9 22; echo "Author:"
tput cup 11 20;echo "Category:"
tput cup 12 20;echo "(sys;system,ref:refence,tb:textbook)"
tput cup 7 30;read title
tput cup 9 30;read author
tput cup 11 30;read category
status=in
echo "$title:$author;$category:$status;$bname:$date" >> ULIB_FILE
tput cup 14 10;echo -e "Any more to add?(Y)es or (N)o>_\b\c"
read answer
        case $answer in
        [Yy]*)  answer=y;;
            *)  answer=n;;
        esac
done
exit 0

#update
OLD_IFS="$IFS"
answer=y
while [ "$answer" = y ]
do
new_status= ; new_bname= ; new_date=
tput clear
tput clear; tput cup 3 5; echo -e "Enter the Author/Title>_\b\c"
read response
grep -i "$response" ULIB_FILE > TTEMP
if [ -s TTEMP ]
then
IFS=":"
read title author category status bname date < TTEMP
tput cup 5 10
echo "UNIX Library - ${BOLD}UPDATE STATUS MODE${NORMAL}"
tput cup 7 23; echo "Title: $title"
tput cup 8 22; echo "Author:$author"
case $category in
        [Tt][Bb]) word=textbook ;;
    [Ss][Yy][Ss]) word=system;;
    [Rr][Ee][Ff]) word=reference;;
               *) word=undefined ;;
esac
tput cup 9 20; echo "category:$word"
tput cup 10 22;echo "Status:$status"
if [ "$status" = "in" ]
then
new_status=out
tput cup 11 18; echo "New status:$new_status"
tput cup 12 14; echo -e "Checked out by:_\b\c"
read new_bname
new_date='date+%D'
tput cup 13 24; echo "Date:$new_date"
else
new_status=in
tput cup 11 14;echo "Checked out by:$bname"
tput cup 12 24:echo "Date:$date"
tput cup 15 18;echo "New status:$new_status"
fi
grep -iv "$title:$author:$category:$status:$bname:$date" ULIB_FILE > TEMP
cp TEMP ULIB_FILE
echo "$title:$author:$category:$new_status:$new_date" >> ULIB_FILE
else
tput cup 7 10 ;echo "respone not found"
fi
tput cup 16 10;echo -e "Any more to update?(Y)es or (N)o>_\b\c"
read answer
case $answer in
 [Yy]*)  answer=y;;
     *)  answer=n;;
esac
done
IFS="$OLD_IFS"
rm TEMP TTEMP
exit 0

#display
#
#display
#
OLD_IFS="$IFS"
answer=y
while [ "$answer" = y ]
do
tput clear;tput cup 3 5; echo -e "Enter the Anthor/Title>_\b\c"
read response
grep -i "$response"  ULIB_FILE > TEMP
if [ -s TEMP ]              #if it is found
then
        IFS=":"
        read title author category status bname date < TEMP
        tput cup 5 10
        echo "UNIX Library-${BOLD}DISPLAYMODE${NORMAL}"
        tput cup 7 23;echo "Title:$title"
        tput cup 8 22;echo "Author:$author"
        case $category in
                [Tt][Bb]) word=textbook;;
             [Ss][Yy][Ss]) word=system;;
             [Rr][Ee][Ff]) word=reference;;
                        *) word=undefined;;
        esac
tput cup 9 20; echo "Category:$word"
tput cup 10 22; echo "status:$status"
if [ "$status" = "out" ]
then
tput cup 11 14;echo "Checked out by:$bname"
tput cup 12 24;echo "Date:$date"
fi
else
tput cup 7 10; echo "$response not found"
fi
tput cup 15 10;echo -e "Any more to look for?(Y)es or (N)0>_\b\c"
read answer
case $answer in
   [Yy]*) answer=y;;
       *) answer=n;;
esac
done
rm TEMP
IFS="$OLD_IFS"
exit 0

#delete
OLD_IFS="$IFS"
answer=y
while [ "$answer" = y ]
do
 tput clear ; tput cup 3 5 ; echo -e "Enter the Author/Title>_\b\c"
 read response
 grep -i "$response" ULIB_FILE >TEMP
 if [ -s TEMP ]
 then
 IFS=":"
 read title author category status bname date < TEMP
 tput cup 5 10
 echo "UNIX Library - ${BOLD}DELETEMODE${NORMAL}"
 tput cup 7 23 ; echo "Title:$title"
 tput cup 8 22 ; echo "Author:$author"
 case $category in
       [Tt][Bb]) word=textbook ;;
   [Ss][Yy][Ss]) word=system ;;
   [Rr][Ee][Ff]) word=reference ;;
              *) word=undefined ;;
 esac
 tput cup 9 20 ; echo "Category: $word"
 tput cup 10 22 ; echo "status:$status"
 if [ "$status" = "out" ]
 then
 tput  cup 11 14 ; echo "Checked out by:$bname"
 tput  cup 12 24 ; echo "Date:$date"
 fi
 tput cup 13 20 ; echo -e "Delete this book? (Y)es or (N)o>_\b\c"
 read  answer
 if [ $answer = y -o $answer = Y ]
 then
 grep -iv "$title:$author:$category:$status:$bname:$date" ULIB_FILE > TEMP
 mv TEMP ULIB_FILE
 fi
 else
  tput cup 7 10 ; echo "$response not found"
 fi
 tput cup 13 20 ; echo -e "Any more to delete? (Y)es or (N)o>_\b\c"
 read answer
 case $answer in
     [Yy]*) answer=y ;;
         *) answer=n ;;
 esac
 done
 IFS="$OLD_IFS"
 rm TEMP
 exit 0
  #report_no
#
#
IFS=":"
case $1 in
   1 ) sort -f -d -t : ULIB_FILE > TEMP ;;
   2 ) sort -f -d -t : +1 ULIB_FILE > TEMP ;;
   3 ) sort -f -d -t : +2 ULIB_FILE > TEMP ;;
esac
#
while read title author category status bname date
do
 echo "   Title:$title" >> PTEMP
 echo "   Author:$author" >> PTEMP
 case $category in
       [Tt][Bb]) word=textbook ;;
   [Ss][Yy][Ss]) word=system ;;
   [Rr][Ee][Ff]) word=reference ;;
              *) word=undefined ;;
 esac
 echo "  Category:$word" >> PTEMP
 echo -e "  Status:$status\n" >> PTEMP
if [ "$status" = "out" ]
then
 echo "  Check out by:$bname" >> PTEMP
 echo "  Date:$date \n" >> PTEMP
fi
echo >> PTEMP
done < TEMP
#
#
pg -c -p "Page %d:" PTEMP
rm TEMP PTEMP
exit 0
  运行shell
[root@localhost myaddr]# ./main
               Supper duper unix library

This is  the unix library application
          Please enter any key to continue..._             Unix library-Main menu                     0:exitThis program                     1:EditMenu                     2:Reportsmenu                     Enter your choice>_ ......(略)
 
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载