zoukankan      html  css  js  c++  java
  • shell下TCL脚本写的一个通讯录小程序

    当年在武汉一家公司实习时,闲暇写的一个通讯录的管理程序。

    包含基本的增删查询功能,麻雀虽小,五脏俱全。

    这仅仅是一个初稿,大家有兴趣可以修改一下接着用。

    #! /bin/bash
    
    #keywords for records
    #name,tel,QQ,mail,Address,others
    
    temperary_filename=''
    
    trap 'rm $temperary_filename' EXIT
    #using trap command to delete temperary file
    
    name=''
    tel=''
    QQ=''
    mail=''
    addr=''
    others=''
    #varibles for program 
    #menu-----user choose options
    #tmp -----temperary varibles
    menu=''
    tmp=''
    #current path for this program
    current_path=''
    option_select() {
    echo "          ******please select your choice************"
    echo "          ******  a---select to add a new record  *******"
    echo "          ******  d---select to delete to a record  *****"
    echo "          ******  f---select to find a record  **********"
    echo "          ******  r---select to revise a record  ********"
    echo "          ******  l---select to list the records  *******"
    echo "          ******  q---select to quit!  ******************"
    read menu
    }
    save_information() {
            echo "save information in record file"
            echo "name:$name"                >>record_file.txt
            echo "tel:$tel"                  >>record_file.txt
            echo "QQ:$QQ"                    >>record_file.txt
            echo "address:$addr"     >>record_file.txt
            echo "others:$others"    >>record_file.txt
            echo ""                                  >>record_file.txt
    }
    records_clear() {
            name=''
            tel=''
            QQ=''
            addr=''
            others=''
    }
    get_keywords() {
            echo "At least,you should input the name and tel for a record"
            echo "and you can input 'q' to exit after you input the tel "
            echo "press any key to continue"
            read tmp
            echo "please input the name:"
            read name
            echo "please input the tel:"
            read tel
            echo "please input the QQ number:"
            read QQ
            if [ $QQ = "q" ] 
            then 
                    QQ=''
                    save_information
                    records_clear
                    return 0
            fi
            echo "please input the address:"
            read addr
        if [ $addr != "q" ]
            then
                    addr=''
                    save_information #save records information to record_file.txt
                    records_clear    #clear the keywords of records
                    return 0
            fi
            echo "please input ohter infomation for records"
            read other
            if [ $other != "q" ]
            then
                    other=''
                    save_information
                    records_clear
                    return 0
            fi
    }
    #add a record 
    add_record() {
            echo "choose to add a record"
            get_keywords
    
    }
    delect_record() {       
            echo "choose to add a record"
            echo "please input the name"
            read tmp
    #creating a temperary file,$$ is the pid of this shell program
            #tmp=$(pwd)             #get current shell program file path
            temperary_filename=$$
            #mkdir {tmp}/tempdir
            #echo $temperary_filename
            touch $temperary_filename
            grep -n "^name:$tmp" record_file.txt | cat -n >$temperary_filename
            cat -n  $temperary_filename 
        tmp=`cut -c 6-6 $temperary_filename` #to get the line number
            echo $tmp #print the line numer
    #       for i in 0 1 2 3 4 5 
    #       do
    #               j=$(($tmp+$i))
    #               echo $j
    #               sed ''$j'd' -i record_file.txt
    #       done
        #using piple to show search result
            
            
    }
    find_record() {
            echo "find a record"
    }
    revise_record() {
            echo "revise_record"
    }
    list_records() {
            cat -n record_file.txt | less
    }
    option_action() {
            case $menu in
                    a | A) add_record;;
                    d | D) delect_record;;
                    f | F) find_record;;
                    r | R) revise_record;;
                    l | L) list_records;;
                    *) echo "no option";;
            esac
    }
    
    #now all the functions have been defined and all the varibles have been 
    #declared,then it willl go into the 
    
    # before this program runs, check whether the record_file exits or not
    # if it does not exists,we create for it
    # record_file record the information for records,such as name,tel,QQ,and
    # so on
    if [ -f record_file ]
    then
            echo ""
    else
            touch record_file.txt
            echo ""
    fi
    
    #add a 
     between the command line and proram mune
    while [ "$menu" != "q" ]
    do
            option_select # select the option 
            option_action # act to the option
    #       read menu
    done
    echo "choice to exit the shell program"
    exit 0
  • 相关阅读:
    System.TypeInitializationException 类型初始值设定项引发异常
    asp.net webapi下json传值方式
    The remote name could not be resolved: 'nuget.org'(未能解析此远程名称:’nuget.org’)
    关于集成Paypal Express Checkout支付功能
    Syntax error at line 16 while loading: expected ')', got keyword 'in' or(i.isArray(t)||(t in e?t=[t]:(t=i.came
    如何在MVC3 razor视图下的ViewsStart文件中设置使用两套不同的Layout布局视图
    knockout使用技巧:告知knockout忽略页面容器内特定部分的绑定
    LINQ to Entities已知问题及注意事项
    jQuery中.live()方法的使用方法
    Uncaught TypeErroe: Uncaught TypeError: Cannot call method 'push' of undefined 和 Uncaught TypeError: undefined is not a function
  • 原文地址:https://www.cnblogs.com/farbeyond/p/5196791.html
Copyright © 2011-2022 走看看