Ãâ·Ñ×¢²á ²é¿´ÐÂÌû |

Chinaunix

  ƽ̨ ÂÛ̳ ²©¿Í ÎÄ¿â
×î½ü·ÃÎÊ°å¿é ·¢ÐÂÌû
²é¿´: 2673 | »Ø¸´: 7
´òÓ¡ ÉÏÒ»Ö÷Ìâ ÏÂÒ»Ö÷Ìâ

ͨѶ¼ϵͳ½Å±¾£¨Ð޸İ棩 [¸´ÖÆÁ´½Ó]

ÂÛ̳»ÕÕÂ:
0
Ìøתµ½Ö¸¶¨Â¥²ã
1Â¥ [ÊÕ²Ø(0)] [±¨¸æ]
·¢±íÓÚ 2005-03-21 15:01 |Ö»¿´¸Ã×÷Õß |µ¹Ðòä¯ÀÀ
Ç°¼¸ÌìÔÚÕâÀï·¢Á˸öͨѶ¼ϵͳµÄ½Å±¾£¬¸Ð¾õÓеĵط½ºÜ¿ºÓ࣬½ñÌìÐÞ¸ÄÁËһϣ¬¸Ð¾õ±È½ÏºÃÁË£¬ÁíÍâ°Ñedit¹¦ÄÜÒ²¼ÓÉÏÈ¥ÁË^_^
main½Å±¾£º
#!/bin/sh

source unit
source addperson
source showperson
source delperson
source editperson

function menu()
{
echo -e "\33[34m"
cat << EOF
        What you want to do? Please input you choice:

                [1] Add a person into the address book!
                [2] Find out a person's data in the address book!
                [3] Delete a person from the origin address book!
                [4] Edit a person's origin data!
                [5] Quit without do anything!
       
EOF
echo -ne "lease select [ 1, 2, 3, 4  or 5 ]:\33[0m"

while read choice
        do
                case $choice in
                        1 ) add;;
                        2 ) show ;;
                        3 ) delete ;;
                        4 ) edit ;;
                        5) echo ByeBye!; exit 0 ;;
                        * ) echo -ne "\33[31mError! Please input [ 1, 2, 3, 4 or 5 ]:  \33[0m";;
                esac
done
}

checkfile
echo -e "\33[32m\t\tWellcome to My addressbook!\33[0m"
menu

ÂÛ̳»ÕÕÂ:
0
2Â¥ [±¨¸æ]
·¢±íÓÚ 2005-03-21 15:03 |Ö»¿´¸Ã×÷Õß

ͨѶ¼ϵͳ½Å±¾£¨Ð޸İ棩

function checkfile ()
{
        if [ ! -f  "addressbook"  ]; then
                echo > addressbook
        fi
}

function response ()
{
        unset answer
        while read
        do
                case $REPLY in
                        y|Y|[Yy][Ee][Ss] ) answer="y";break ;;
                            n|N|[Nn][Oo] ) answer="n";break;;
                                         q|Q )  menu;;
                                            * )  echo  "Error! Please input y or n or q (quit to main menu )!" ;;
                esac
        done
}

function update ()
{
        awk -F: -v new=$oldname '{ if ( $1 != new ) print $0; }' addressbook  > /tmp/tmp$$
        mv -f /tmp/tmp$$ addressbook 2> /dev/null
        if [ ! -z "$name" ]; then
                echo $namemailaddressphonemobilemessage >> addressbook
                return 0
        else  return 1
        fi
}

ÂÛ̳»ÕÕÂ:
0
3Â¥ [±¨¸æ]
·¢±íÓÚ 2005-03-21 15:04 |Ö»¿´¸Ã×÷Õß

ͨѶ¼ϵͳ½Å±¾£¨Ð޸İ棩

function checkperson ()
{
        if [ -z "$name" ]; then
                echo -e "\33[31mError! the Name is incorrect!\n Please Input the person's name and other messages again: \33[0m"
                addperson
        fi
        showname
        if [ $? -eq 0 ]; then
                echo  -e  "\33[31mThe name you input has already exist! Do you want to delete the origin name? \33[0m\n\t\t\t[ y or n or q ( quit to main menu )]"
                response
                if [ "$answer" == "y" ]; then
                        oldname=$name
                        unset name
                        update
                        if [ $? -eq 1 ]; then
                                echo The origin name is deleted now!
                                name=$oldname
                                unset oldname
                        fi
                elif [ "$answer" = "n" ]; then
                        echo Input a New Name Again:
                        read name
                        checkperson
                        check
                        identify
                fi
        fi
}

function checkmail ()
{
        if [ -z $mail ]; then mail="user@localhost.localdomain"; fi
        mail_check=`echo $mail | sed -n '/\@*\./p'`
        if [ -z $mail_check ]
                then
                        echo -ne "The E-mail you input is incorrect!\nPlease input again: "
                        read  mail
                        checkmail
        fi
}

function checkphone ()
{
        if [ -z "$phone" ]; then phone=0; fi
        if [ -z "$mobile" ]; then mobile=0; fi
        phone_check=`echo $phone | tr ':;",.+<>?/~\!=@#$%^&*[a-zA-Z]{}|' ' ' `
        mobile_check=`echo $mobile | tr ':;",.+<>?/~\!=@#$%^&*[a-zA-Z]{}|' ' ' `
        if [ "$phone_check" != "$phone" ]
                then
                        echo -ne "The Phone Number you input is incorrect!\nPlease input again: "
                        read phone
                        checkphone
        elif [ "$mobile_check" != "$mobile" ]
                then
                        echo -ne "The Mobile Phone Number you input is incorrect!\nPlease input again: "
                        read mobile
                        checkphone
        fi
}
                       
function redo ()
{
        select pick in "Name" "E-mail" "Address" "hone Number" "Moblie Phone Number" "Other Messages" "Exit to the identify menu" "Exit to the main menu" "Quit without save"
                do
                case $pick in
                        Name )
                                echo Please input the name again:
                                read name
                                checkperson
                                redo
                        ;;
                        E-mail )       
                                echo Please input the E-mail again:
                                read mail
                                checkmail
                                redo
                        ;;
                        Address )
                                echo Please input the address again:
                                read address
                                redo
                        ;;
                        "hone Number" )
                                echo Please input the phone number again:
                                read phone
                                checkphone
                                redo
                        ;;
                        "Moblie Phone Number" )
                                echo Please input the mobile phone number again:
                                read mobile
                                checkphone
                                redo
                        ;;
                        "Other Messages" )
                                echo Please input the other messages again:
                                read message
                                redo
                        ;;
                        "Exit to the main menu" )
                                menu
                        ;;
                        "Exit to the identify menu" )
                                identify
                        ;;
                        "Quit without save" )
                                exit 0
                        ;;
                        * )        echo -e "This is not a valid choice. Try again:"
                                pick=
                        ;;
                esac
        done
}

function identify ()
{
        cat << DATA
        The data you input is on the next:

                Name: $name
                E-mail: $mail
                Address: $address
                Phone Number: $phone
                Mobile Phone Number: $mobile
                Other Message: $message

        Is it right?[ y or n ]:
DATA
        response
        if [ "$answer" = "y" ]; then
                update
                if [ $? -eq 0 ]; then
                        echo The Data is updated successfully!
                fi
                echo -e "\33[32mWhat you want to do next ? Select in the main menu!\33[0m"
                menu
        elif [ "$answer" = "n" ]; then
                echo -e "\33[35mWhich one you want to change? Pick out it :\33[0m"
                redo
        fi
}
       
function check ()
{
        checkperson
        checkmail
        checkphone
        if [ -z "$address" ]; then address="Null"; fi
        if [ -z "$message" ]; then message="Null"; fi
}

function addperson ()
{
        echo -n "Input the Name: "; read name ;
        echo -n "Input the E-mail: "; read mail ;
        echo -n "Input the Address: "; read address ;
        echo -n "Input the Phone Number: "; read phone ;
        echo -n "Input the Mobile Phone Number: "; read mobile ;
        echo -n "Input the other messages if necessary: "; read message ;
        check;
        identify;
}

function add ()
{
                echo Please  follow the next steps !
                stty erase '^?'
                addperson
}

ÂÛ̳»ÕÕÂ:
0
4Â¥ [±¨¸æ]
·¢±íÓÚ 2005-03-21 15:06 |Ö»¿´¸Ã×÷Õß

ͨѶ¼ϵͳ½Å±¾£¨Ð޸İ棩

function deldata ()
{
        showname
        if [ $? -eq 1 ]; then
                echo  -e "\33[31mThe person you want to delete does not exist! Please check the name first!:\33[0m"
                menu
        else
                echo -e "The person 's data is :\n$showname"
                echo -ne "\33[34m\tIs it right? \33[0m[ y or n ]: "
                response
                if [ "$answer" == "y" ]; then
                        oldname=$name
                        unset name
                        update
                        if [ $? -eq 1 ]; then
                                echo The origin name is deleted now!
                                echo Do you want to delete another person\'s data? [ "y" to continue and "q" will return to the main menu]
                                response
                                if [ "$answer" == "y" ]; then
                                        delete
                                else menu
                                fi
                        fi

                else
                        echo -e "\33[31mThe person's data you want to delete may not exist!\n\33[0m\tSkip to the main menu ->"
                        menu
                fi
        fi
}
               
function delete ()
{
        echo -n "Type the name you want to delete [ No input will skip to main menu! ]:  "
        read name
        if [ -z "$name" ]; then
                menu
        else
                deldata
        fi
}

ÂÛ̳»ÕÕÂ:
0
5Â¥ [±¨¸æ]
·¢±íÓÚ 2005-03-21 15:08 |Ö»¿´¸Ã×÷Õß

ͨѶ¼ϵͳ½Å±¾£¨Ð޸İ棩

function confirm ()
{
        response
        if [ "$answer" = "y" ]; then
                show
        else menu
        fi
}

function showname ()
{
        showname=`awk -F: -v new=$name '{ if ( $1 == new ) print $0; }' addressbook | awk -F: '{ printf "%-10s%s\n%-10s%s\n%-10s%s\n%-10s%s\n%-10s%s\n%-10s%s\n\n", "Name: ", $1, "E-mail: ",$2,  "Address: ", $3,  "hone Number: ", $4,  "Moblie Phone Number: ", $5, "Other Messages: ", $6 ; }' `
        if [ -z "$showname" ]; then
                return 1
        else  return 0
        fi
}

function showall ()
{
        awk -F: '{ printf "%-10s%s\n%-10s%s\n%-10s%s\n%-10s%s\n%-10s%s\n%-10s%s\n\n", "Name: ", $1, "E-mail: ",$2,  "Address: ", $3,  "hone Number: ", $4,  "Moblie Phone Number: ", $5, "Other Messages: ", $6 ; }' addressbook
}

function show ()
{
        echo -ne "\33[33mWhose data  you want to know ? \33[34mType his or her name directly \n\33[0m[ Type "all" to show all data, and No input will skip to main menu!]:  "
        read name
        if [ "$name" == "all" ];        then
                showall
                echo -e "\33[33mContinue to check out datus? \33[0m[ "y" to continue and "q" will return to the main menu ]"
                confirm
        elif [ -z "$name" ]; then
                menu
        else
                showname
                if [ $? -eq 1 ]; then
                        echo -e "\33[31mThe person you want to know does not exist! \33[34mCheck again!\33[0m"
                        show
                else
                        echo -e "$showname"
                        echo "Do you want to check another person's data? [ "y" to continue and "q" will return to the main menu ]"
                        confirm
                fi
        fi
}

ÂÛ̳»ÕÕÂ:
0
6Â¥ [±¨¸æ]
·¢±íÓÚ 2005-03-21 15:10 |Ö»¿´¸Ã×÷Õß

ͨѶ¼ϵͳ½Å±¾£¨Ð޸İ棩

function group ()
{
        local i=2
        while [ $i -le 6 ]
        do
                groupname[$i]=`echo -e "$showname" | awk -F: -v num=$i '{ if ( NR == num ) print $2; }'`
                let  i++
        done
        mail=${groupname[2]}; address=${groupname[3]}; phone=${groupname[4]}; mobile=${groupname[5]}; message=${groupname[6]}
}

function edit ()
{
        echo -ne "\33[34mWhose data you want to edit?\33[0m\n [ Type "all" to show all people's data, and No input will skip to main menu! ]:  "
        read
        if [ "$REPLY" == "all" ]; then
                showall
                edit
        elif [ -z "$REPLY" ]; then
                menu
        else
                name=$REPLY
                showname
                if [ $? -eq 1 ]; then
                        echo -e "\33[35mThe person you want to edit does not exist! Please try again! \33[0m"
                        edit
                else
                        echo -e "The person's data is :\n\33[32m$showname\33[0m\nNow you can change it as follow [make a chioce]:"
                        group
                        oldname=$name
                        unset name
                        update
                        name=$oldname
                        unset oldname
                        redo
                fi
        fi
}

ÂÛ̳»ÕÕÂ:
0
7Â¥ [±¨¸æ]
·¢±íÓÚ 2005-03-21 15:12 |Ö»¿´¸Ã×÷Õß

ͨѶ¼ϵͳ½Å±¾£¨Ð޸İ棩

ÐÞ¸ÄÁËÖ®ºó£¬ËäÈ»¶àÁ˸öeditperson½Å±¾£¬µ«ÎÒÓÃawk¿´ÁËÒ»ÏÂÐÐÊý¾ÓÈ»±ÈÔ­À´µÄ»¹ÉÙ£¬¿´À´×ÊÔ´ÀûÓû¹ËãºÃ°É^_^

ÂÛ̳»ÕÕÂ:
0
8Â¥ [±¨¸æ]
·¢±íÓÚ 2005-07-24 18:28 |Ö»¿´¸Ã×÷Õß

ͨѶ¼ϵͳ½Å±¾£¨Ð޸İ棩

ûÓп´¶®£¬·´ÕýÊDz»ÔËÐС£
ÄúÐèÒªµÇ¼ºó²Å¿ÉÒÔ»ØÌû µÇ¼ | ×¢²á

±¾°æ»ý·Ö¹æÔò ·¢±í»Ø¸´

  

±±¾©Ê¢ÍØÓÅѶÐÅÏ¢¼¼ÊõÓÐÏÞ¹«Ë¾. °æȨËùÓÐ ¾©ICP±¸16024965ºÅ-6 ±±¾©Êй«°²¾Öº£µí·Ö¾ÖÍø¼àÖÐÐı¸°¸±àºÅ£º11010802020122 niuxiaotong@pcpop.com 17352615567
δ³ÉÄê¾Ù±¨×¨Çø
Öйú»¥ÁªÍøЭ»á»áÔ±  ÁªÏµÎÒÃÇ£ºhuangweiwei@itpub.net
¸ÐлËùÓйØÐĺÍÖ§³Ö¹ýChinaUnixµÄÅóÓÑÃÇ ×ªÔر¾Õ¾ÄÚÈÝÇë×¢Ã÷Ô­×÷ÕßÃû¼°³ö´¦

Çå³ý Cookies - ChinaUnix - Archiver - WAP - TOP