Shell CD recording Application

Source: Internet
Author: User

From the "Linnux program design," the second chapter, from one by one to knock out, the conclusion is that a few s did not come out effect

#。 /bin/sh and #. There's a difference,/bin/bash.

The first direct typing is the former, always output some-E, indicating that do not understand


#!/bin/bash # Very Simple example shell script for managing a CD collection # Copyright (C) 1996-2007 Wiley Publishing in C menu_choice= "" Current_cd= "" title_file= "title_cdb" tracks_file= "tracks.cdb" temp_file=/tmp/cdb.$$ trap ' rm-f $tmp _ File ' EXIT Get_return () {ECHO-E "press RETURN \c" read x return 0} get_confirm () {ECHO-E "Are do you sure?" \c "While true does read x case" $x "in Y | Yes | Y | Yes |
		 YES) return 0;; n | No | N | NO |
		 No) echo echo "Canceled" 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 cou NT 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 () {echo $* >&Gt $title _file return} insert_track () {echo $* >> $tracks _file return} add_record_tracks () {echo "Enter track I nformation for this CD ' echo ' When no more tracks enter Q ' cdtrack=1 cdttitle= ' while [' $cdttitle '!= ' Q '] do EC Ho-e "Track $cdtrack, Track title?
		\c "read tmp cdttitle=${tmp%%,*} if [$tmp"!= "$cdttitle"];then echo "sorry,no command 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} add_records () {# Prompt for the initial information echo-e ' Enter catalog name \c ' Read TMP Cdcatnum=${tm
	
	p%%,*} echo-e "Enter title \c" Read tmp cdtitle=${tmp%%,*} echo-e "Enter type \c" read tmp cdtype=${tmp%%,*}  Echo-e "Enter Artist/composer \c" read tmp cdac=${tmp%%,*} # Check that they want to Enter the information echo About to add new entry echo "$cdcatnum $cdtitle $cdtype $CDAC "# If confirmed the appen it to the titles file if get_confirm; Then Insert_title $cdcatnum, $cdtitle, $cdtype, $cdac add_record_tracks else remove_records fi return} FIND_CD () {if ["$" = "n"];then asklist=n else asklist=y fi cacatnum= "Echo-e" Enter a string to search for the CD
	
	Title \c "Read Searchstr if [" $searchstr "=" "];then return 0 fi grep" $searchstr "$title _file > $temp _file
		Set $ (wc-l $temp _file) linesfound=$1 case ' $linesfound ' in 0) echo ' Sorry, nothing found ' get_return return 0
	;;
	1);; 2) echo "Sorry,not unique" echo "found the following" cat $temp _file get_return retrun 0 esac ifs= "," read CD Catnum cdtitle Cdtype Cdac < $temp _file ifs= "" If [-Z "$cdcatnum"];then echo "sorry.could not exact catalog field from $temp _file "Get_return return 0 fi echo Catalog number $cdcatnum echo Title: $cdtitle echo Type : $cdtype echo Artist/composer: $cdac
	echo Get_return If ["$asklist" = "Y"]; Then ECHO-E "View tracks for this CD? \c" Read x if ["$x" = "y"];then echo list_tracks echo fi fi r Eturn-1} update_cd () {If [-Z "$cdcatnum"]; then echo "You must select a CD-i" Find_cd n FI-if [ñ "$cdcat Num "];  Then echo "Current tracks are:-" list_tracks echo echo "This'll re-enter the tracks for $cdtitle" Get_confirm && {grep-v "^${cdcatnum}," $tracks _file > $temp _file mv $temp _file $tracks _file Echo add_record_
	Tracks} Fi return} Count_cds () {set $ (wc-l $title _file) num_titles=$1 set $ (wc-l $tracks _file) num_tracks=$1 Echo found $num _titles cds,with A total of $num _tracks tracks Get_return return} remove_records () {if [-z] $cdcatnu M "]; Then echo you must Select a CD-i find_cd n fi if [-N "$cdcatnum"]; Then echo "You are about to delete $cdtitle" get_confirm && {grep-v "^s{cdcatnum}," $title _file > $tem P_fiLe MV $temp _file $title _file grep-v "^${cdcatnum}," $tracks _file > $temp _file mv $temp _file $tracks _file C Dcatnum= "" "Echo Entry removed} get_retrun fi return} list_tracks () {if [" $cdcatnum "="]; Then echo no CD selected yet return else grep "^${cdcatnum}," $tracks _file > $temp _file num_tracks=$ (wc-l $te Mp_file) If ["$num _tracks" = "0"]; Then echo no tracks found for $cdtitle else {echo echo $cdtitle:-"echo cut-f 2-D, $temp _file EC HO} | ${pager:-more} fi fi Get_return return} rm-f $temp _file if [!-F $title _file];then touch $title _file fi if [ ! -F $tracks _file];then touch $tracks _file fi * Now application proper clear echo echo "Mini CD Manager" sleep
1 quit=n while ["$quit"!= "Y"];
		Do set_menu_choice case "$menu _choice" in a) add_records;;
		R) Remove_records;;
		f) find_cd_y;;
		u) update_cd;;
		c) Count_cds;;
		l) list_tracks;;
		b) echo more $title _file Echo	Get_return;; Q |
		Q) quit=y;;
	*) echo "Sorry.choice not recognized";;






















 Esac #Tidy up and leave rm-f $temp _file echo "finished" Exit 0


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.