linux程序设计第2章末程序1

来源:互联网 发布:软件卸载大师 编辑:程序博客网 时间:2024/05/21 10:38
#!/bin/bashmenu_choice=""current_cd=""title_file="title.cdb"tracks_file="tracks.cdb"temp_file=/tmp/cdb.$$trap 'rm -f $temp_file' EXITget_return(){    echo -e "Press return \c"    read x    return 0}get_confirm(){   echo -e "Are you sure? \c"   while true   do       read x       case "$x" in           y | yes | Y | Yes | YES )              return 0;;           n | no | N | No | NO )              echo              echo "Cancelled"              return 1;;           *) echo "Please enter yes or no";;       esac   done}set_menu_choice() {    clear    echo "Options :-"    echo     echo "    a) Add new CD"    echo "    f) Find CD"    echo "    c) Count the CDs and tracks in the catalog"    if [ "$cdcatnum" != "" ]; then        echo "    l) List tracks on $cdtitle"        echo "    r) Remove $cdtitle"        echo "    u) Update track information for $cdtitle"    fi    echo "    q) Quit"    echo    echo -e "Please enter choice then press return \c"    read menu_choice    return}insert_title(){#将所有的参数写入到title_file文件中    echo $* >> $title_file     return}insert_track(){    #将所有的参数写入到tracks_file文件中    echo $* >> $tracks_file    return}add_record_tracks(){    echo "Enter track information for this CD"    echo "When no more tracks enter q"    cdtrack=1    cdttitle=""    while [ "$cdttitle" != "q" ]    do        echo -e "Track $cdtrack,track title? \c"        read tmp#将输入参数进行格式化,去除第一个逗号以及后面的内容        cdttitle=${tmp%%,*}        if [ "$tmp" != "$cdttitle" ];then            echo "Sorry, no commas allowed"            continue        fi#检查字符串是否为空        if [ -n "$cdttitle" ];then            if [ "$cdttitle" != "q" ];then                insert_track $cdcatnum,$cdtrack,$cdttitle            fi        else            cdtrack=$((cdtrack-1))        fi     cdtrack=$((cdtrack+1))   done}


0 0
原创粉丝点击