LinuShell程序设计试验_第1页
LinuShell程序设计试验_第2页
LinuShell程序设计试验_第3页
LinuShell程序设计试验_第4页
全文预览已结束

付费下载

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Linux shell 程序设计实验指南请在vi 中逐一编辑并执行以下10 个shell脚本程序,然后结合所学知识和程序的输出分析各程序中各语句的含义:1.编写一个简单的回显用户名的shell程序。#!/bin/bash#filename:dateecho Mr.$USER,Today is:echo 'date'echo Whish you a lucky day!2.使用 if -then 语句创建简单的shell 程序。#!/bin/bash#filename:bbbbecho -n Do you want to continue: Y or Nread ANSWERif

2、 $ANSWER=N-o $ANSWER=n thenexitfi3.使用 if -then-else 语句创建一个根据输入的分数判断是否及格的shell程序。#!/bin/bash#filename:akecho -n please input a score:read SCOREecho You input Score is $SCOREif $SCORE-ge 60 ;thenecho -n Congratulation!You Pass the examination.elseecho -n Sorry!You Fail the examination!fiecho -n press

3、any key to continue!read $GOOUT4.使用case 语句创建一个菜单选择的shell程序。#!/bin/bash#filename:za#Display a menuecho _echoRestoreechoBackupechoechoUnload#Read and excute the user's selectionecho -n Enter Choice:read CHOICEcase $CHOICE in1) echo Restore;2) echo Backup;3) echo Unload;*) echo Sorry $CHOICE is not

4、 a valid choiceexit 1esac5.使用 for 语句创建简单的#!/bin/bash#filename:mmfor ab in 1 2 3 4doecho $abdoneshell程序。6.使用 for 语句创建求命令行上所有整数之和的#!/bin/bash#filename:qqqsum=0for INT in $*dosum='expr $sum + $INT'doneecho $sumshell程序。7.使用 while语句创建一个计算1-5的平方的shell程序。#!/bin/bash#filename:zxint=1while $int-le 5

5、dosq='expr $int * $int'echo $sqint='expr $int + 1'doneecho Job completed8.使用 while 语句创建一个根据输入的数值求累加和(#!/bin/bash#filename:sumecho -n Please Input Number:read NUMnumber=0sum=0while $number-le $NUM doecho numberecho $numbernumber=' expr $number + 1 'echo sumecho $sumsum=' e

6、xpr $sum + $number 'doneecho1+2+3+4+n)的shell程序。9.使用 until 语句创建一个计算#!/bin/bash#filename:xxint=1until $int- gt 5 dosq='expr $int * $int'echo $sqint='expr $int + 1'doneecho Job completed1-5的平方的shell程序。10.使用 until语句创建一个输入exit退出的shell程序。#!/bin/bash#filename:hkecho This example is for test until.doecho If you input exit then quit the systemecho -n please input:read EXITuntil $EXIT = exit dor

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论