《Linux程序设计》第四版第二章 我的第一个shell程序:CD唱片应用程序

1. 书籍《Linux程序设计》第四版 Neil Mattew,Richard Stones著,第二章中书中用shell写了一个CD 唱片程序,仿照它,我自己大概实现了其功能,代码如下:

文件:manageCd.sh

#!/bin/bash
# this program aims to manage CD and songs contained in the CD
#	history:
#			2014-10-14  first release
# manageCd.sh
mainBoard()
{
  choice=1
until [ $choice == "q" ]
do
	clear
	echo	"options as follow:"
	echo "a) Add new CD"
	echo "v) View CD"
	echo "d) Delete CD"
	echo "f) Find cd"
	echo "c) Count the CD and songs in the catalog"
        echo "u) update CD"
	echo "q) quit"
	echo ""

	read -p "please input your choice: " choice
  while [ "$choice" != "a" -a "$choice" != "v" -a "$choice" != "d" -a "$choice" != "f" -a "$choice" != "c" -a "$choice" != "u" -a "$choice" != "q" ]
  do
  	read -p "input error,please input again([a,v,d,f,c,u]):" choice
  done

  case $choice in
              "a")
		 addNewCD
		 ;;

              "v")
		 viewCD
		 ;;

              "d")
		 deleteCD
		 ;;

	      "f")
                 findCD
 		 ;;
			
              "c")
		 countCDAndSongs
		 ;;

              "u")
		 updateCD
     ;;

     "*")
     echo "error"
     ;;
  esac
  echo -n "press to return"
  read x
done
}

addNewCD()
{
	title_file="title_file"
  songs_file="songs_file"
 
   
  read -p "Enter CD name: " name
  while true
   do
   flag=0
    for x in `awk -F , '{print $1}' $title_file`
     do
       if [ "$name" == "$x" ]; then
        echo -n "CD name:$name has existed,please input CD name again: " 
        read name
        flag=1
        break;
       fi
     done
    
    if [ "$flag" == 0 ]; then
     break;
    fi
   done

  
  
  read -p "Enter CD Title: " title
  read -p "Enter CD Type: " type
  read -p "Enter The artist/composer: " composer

  echo "About to add new entry"
  echo  "$name  $title  $type 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值