ImageVerifierCode 换一换
格式:DOCX , 页数:15 ,大小:195.25KB ,
资源ID:6545810      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/6545810.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(中南大学linux程序设计环境实验三.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

中南大学linux程序设计环境实验三.docx

1、中南大学linux程序设计环境实验三实验3 Linux Shell程序设计1、实验目的(1) 掌握Linux shell程序运行方法 (2) 掌握Linux Shell程序基本语法(3) 了解Linux环境变量(4) 编写简单Linux shell程序 2、实验内容 完成简单CD唱片管理系统。(1) 需求假设你收集了大量的CD唱片,现在为了方便管理,需要设计和实现一个管理CD唱片的程序。程序至少能够把每张CD唱片的资料保存起来,如唱片的名称、音乐类型、艺术家或作曲家的名字等;然后针对某张CD唱片而言,还需要保存一些简单的曲目信息;程序要可以以CD唱片为单位进行搜索,而不是以曲目为单位;为了使程

2、序具备完整性,还需要实现对CD唱片资料的输入、修改和删除等功能。(2) 设计把标题信息和曲目信息分开,用两个文本文件分别来存储。每张CD唱片保存如下信息:编号、标题、曲目类型(流行、爵士等)、作曲家等。曲目只保存下面两个信息:编号和曲名。如下表所示:表1. 唱片信息唱片编号标题曲目类型作曲家CD123Cool saxjazzBixCD234Classic violinclassicBachCD345Hits99popVarious表2. 曲目信息目录编号曲目编号曲名CD1231Some jazzCD1232More jazzCD2341Sonata in D minorCD3451Dizzy各

3、项信息用逗号来分隔。(3) 实现程序共包含如下函数:get_return()get_confirm()set_menu_choice()insert_title()insert_track()add_record_tracks()add_records()find_cd()update_cd()count_cds()remove_records()list_tracks()准确无误代码:#!/bin/bash#Very simple example shell script for managing a CD collection.#Copyright (C) 2012-2013 Centra

4、l South University.menu_choice=current_cd=title_file=title.cdbtracks_file=tracks.cdbtemp_file=/tmp/cdb.$trap rm -f $temp_file EXITget_return() echo -e Press return: c read x return 0get_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 |

5、 No | NO ) echo echo Cancelled return 1; *) echo Please enter yes or no ; esac doneset_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) Up

6、date track information for $cdtitle fi echo q) Quit echo echo -e Please enter choice then press return c read menu_choice returninsert_title() echo $* $title_file returninsert_track() echo $* $tracks_file returnadd_record_tracks() echo Enter track information for this CD echo When no more tracks ent

7、er q cdtrack=1 cdtitle= while $cdtitle != q do echo -e Track $cdtrack, track title? c read tmp cdtitle=$tmp%,* if $tmp != $cdtitle ; then echo Sorry, no commas allowed continue fi if -n $cdtitle ; then if $cdtitle != q ; then insert_track $cdcatnum,$cdtrack,$cdtitle fi else cdtrack=$(cdtrack-1) fi c

8、dtrack=$(cdtrack+1) doneadd_records() # Prompt for the initial information echo -e Enter catalog name: c read tmp cdcatnum=$tmp%,* 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 wa

9、nt to enter the information echo About to add new entry echo $cdcatnum $cdtitle $cdtype $cdac # If confirmed then append it to the titles file if get_confirm; then insert_title $cdcatnum,$cdtitle,$cdtype,$cdac add_record_tracks else remove_records fi returnfind_cd() if $1 = n ; then asklist=n else a

10、sklist=y fi cdcatnum= echo -e Enter a string to search for in the CD titles 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

11、unique. echo Found the following cat $temp_file get_return return 0 esac IFS=, read cdcatnum cdtitle cdtype cdac $emp_file mv $temp_file $tracks_file echo add_record_tracks fi returncount_cds() set $(wc -l $title_file) num_titles=$1 set $(wc -l $tracks_file) num_tracks=$1 echo found $num_titles CDs,

12、 with a total of $num_tracks tracks get_return returnremove_records() if -z $cdcatnum ; then echo You must select a CD first find_cd n fi if -n $cdcatnum ; then echo You are about to delete $cdtitle get_confirm & grep -v “$cdcatnum,” $title_file $temp_file mv $temp_file $title_file grep -v “$cdcatnu

13、m,” $tracks_file $temp_file mv $temp_file $tracks_file cdcatnum= echo Entry removed get_return fi returnlist_tracks() if $cdcatnum = ; then echo no CD selected yet return else grep $cdcatnum, $tracks_file $temp_file num_tracks=$(wc -l $temp_file) if $num_tracks = 0 ; then echo no tracks found for $c

14、dtitle else echo echo $cdtitle :- echo cut -f 2- -d , $temp_file echo | $PAGER:-more fi fi get_return returnrm -f $temp_fileif ! -f $title_file ; then touch $title_filefiif ! -f $tracks_file ; then touch $tracks_filefi# Now the application properclearechoechoecho Mini CD manager sleep 1quit=nwhile $

15、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; esacdone#Tidy up and leaverm -f $temp_fileecho Finished exit 03、实验记录 4、心得体会老师提供的源码里有许多错误,通过对需求的理解以及脚本的分析,得出正确的脚本代码,比如,对$1(数字)的含义不理解,就会把它当成$l(字母),$1(数字)在shell中称为“位置参数”,表示传入的第1个参数,而$l(字母)几乎不存在,除了l(字母)是个变量外。其它类似的还有许多,所以要理解具体语句的含义后才会知道日后怎样去用。

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1