linux shell程序设计实验报告,linux的shell脚本实验报告
《linux的shell脚本实验报告》由会员分享,可在线阅读,更多相关《linux的shell脚本实验报告(7页珍藏版)》请在人人文库网上搜索。
1、第二次实验内容一、实验名称:Linux下shell编程二、实验类型:设计三、实验目的:1 熟悉Linux的shell几种变量使用2 熟练掌握Linux的shell编程几种结构3 熟练掌握Linux下shell脚本的编写四、实验准备参考教材,课件第7章内容及笔记。要求实验内容全部写到实验报告上(B5纸)。五、实验内容1. 练习使用shell四种变量,参考课件例题。用户自定义变量,环境变量,位置变量,特殊变量这四种变量类型的使用,书中有例题。2. 调试课件所有shell脚本的例题。3. 编写如下脚本:l 编写脚本if1,测试其功能。 echo -n word 1: read word1echo -。
2、n word 2: read word2if test $word1 = $word2thenecho Matchfiecho End of program.l 编写脚本chkargs,测试其功能if test $# -eq 0thenecho You must supply at least one argument.exit 1fiecho Program running.l 编写脚本if2,测试其功能if test $# -eq 0thenecho You must supply at least one argument.exit 1fiif test -f $1thenecho $1。
3、 is a regular file in the working directoryelseecho $1 is NOT a regular file in the working directoryfil 编写脚本if3,测试其功能echo -n word 1: read word1echo -n word 2: read word2echo -n word 3: read word3if $word1 = $word2 -a $word2 = $word3 thenecho Match: words 1, 2, & 3elif $word1 = $word2 thenecho Match。
4、: words 1 & 2elif $word1 = $word3 thenecho Match: words 1 & 3elif $word2 = $word3 thenecho Match: words 2 & 3elseecho No matchfil 编写smartzip 脚本,测试其功能#!/bin/bashftype=file $1case $ftype in$1: Zip archive*)unzip $1 ;$1: gzip compressed*)gunzip $1 ;$1: bzip2 compressed*)bunzip2 $1 ;*) echo File $1 can 。
5、not be uncompressed with smartzip;esacl 编写脚本dirfiles,测试其功能。for i in *doif -d $i thenecho $ifidonel 编写脚本until1,测试其功能。用while改写之。secretname=jennyname=nonameecho Try to guess the secret name!echountil $name = $secretname /while改写位 while “$name” != “$secretname” ,其他地方不变doecho -n Your guess: read namedone。
6、echo Very good.l 编写脚本brk,测试其功能。for index in 1 2 3 4 5 6 7 8 9 10doif $index -le 3 ; thenecho continuecontinuefi#echo $index#if $index -ge 8 ; thenecho breakbreakfidonel 编写脚本command_menu,测试其功能。echo -e n COMMAND MENUnecho a. Current date and timeecho b. Users currently logged inecho c. Name of the wor。
7、king directoryecho -e d. Contents of the working directorynecho -n Enter a, b, c, or d: read answerechocase $answer ina)date;b)who;c)pwd;d)ls;*)echo There is no selection: $answer;esacl 编写脚本demo_shift,测试其功能。echo arg1= $1 arg2= $2 arg3= $3shiftecho arg1= $1 arg2= $2 arg3= $3shiftecho arg1= $1 arg2= $。
8、2 arg3= $3shiftecho arg1= $1 arg2= $2 arg3= $3shiftl 编写shell脚本sum1,求命令行上整数和。即:$./sum1 5 12 4 6,给出和的结果。sum=0for i in $*do let sum=sum+idoneecho “和是:$sum”l 编写脚本filetest,判断当前目录下所有文件类型,如果是普通文件,显示文件内容;如果是目录文件,显示目录列表;如果是大小为0的文件,删除它;否则,显示“sorry, The file is not recognized!”for i in *do if -d $i then ls $ie。
9、lif -f $i then if -s $i then cat $ielse rm $ifielseecho n “sorry,the file cant be recognized”fidonel 编写shell脚本user,判断当前登录用户是否为“学号命名”的用户,是,提示:hello “学号用户”,welcome!,否,提示“you should login using your username! ”Read nameIf $USER = $name Then echo “hello $USER”else echo “you should login using your usern。
10、ame!”fil 编写shell脚本menu,使用shell编写一个菜单,分别实现列出以下内容:(1)显示目录内容、(2)切换目录、(3)创建文件、(4)编辑文件、(5)删除文件的l 功能。在此例中将用到循环语句、分支语句和输入输出语句。Echo “a.display the directory”Echo “b.change the directory”Echo “c.create a file”Echo “d.delete the file”Echo “if you input nothing,you will exit”Read itemUntil -z $item Do Case $it。
11、em in a) Echo “input the directory”Read direLs $dire;b) Echo “input the directory you want go into”Read direCd $dire;c) Echo “input the file you want to create”Read fTouch $f;d) Echo “input the file you want to delete”Read fRm $f;EsacEcho “a.display the directory”Echo “b.change the directory”Echo “c。
12、.create a file”Echo “d.delete the file”Echo “if you input nothing,you will exit”Read itemdonel 编写脚本,实现一个简单计算器。+ addition- subtractionx multiplication/ division脚本执行形式:$ ./cal.sh 21 / 3Let l=$1 /最简单的一种形式,而且还特别高效Echo $1;第二种方式:Re=”+ - * /”For var in $reDoIf $var = “*” ThenNum2=$1#*Num1=$1%*ElseNum2=$1#*$varNum1=$1#%$var*FiIf $num1 =$1 Then continueFiCase $var in“+”) let num=num1+num2Break;“-“) let num=num1-num2;Break;“*”)let num=num1*num2Break;“/”)let num=num1/num2Break;EsacDoneEcho $num六、实验总结。
linux shell程序设计实验报告,linux的shell脚本实验报告相关推荐
- 第十章 shell的交互功能与shell程序设计----操作系统原理和实践
什么是shell?shell的用途是啥?_Darren_wdq的博客-CSDN博客_shell的作用场景:只知道写shell脚本,却不知道什么是shell?那shell是什么呢?找到了之前在腾讯课堂上 ...
- shell的建立与执行实验报告_实验指导书--实验02 Linux Shell用户接口
实验二:Linux Shell用户接口 实验学时:2 实验类型:验证 实验要求:必修 一.实验目的 通过本实验的学习,使学生掌握Linux Shell的使用方法. 二.实验内容 实验内容:实践Linu ...
- linux实验三shell程序设计,实验三 LINUX SHELL编程
精选文库 -实验三LINUX SHELL 编程 四.实验内容 本实验包含两个具体的SHELL程序编写任务,较为全面地涉及了SHELL 程序的设计方法和技术.内容如下: 1.创建以下菜单程序: USER ...
- linux 程序实验总结,Linux实验报告(实验四) shell编程实验
实验四 shell编程实验(二) 班级:姓名:学号:上机时间:年月日 任课教师:实验教师:实验成绩: 一.实验目的 综合Linux常用命令和vi编辑器的使用,熟练掌握shell脚本编程. 二.实验注意 ...
- 西南科技大学Linux实验名称:实验六 Linux环境的Shell程序设计
1. 实验记录 实验一 实验二 实验三 实验四 实验五 实验六 实验七 实验八 实验九 实验十 实验十一 实验十二 2. 思考题回答 1.Shell脚本中的程序段有错误,但该程序段在运行中没有被执行, ...
- linux程序设计项目报告,Linux程序设计实验报告大作业
Linux程序设计实验报告大作业 实 验 报 告 课程名称: LINUX程序设计 学 院: 计算机学院 专 业: 软件工程 班 级: 14-3 姓 名: 张正锟 学 号: 201401061038 2 ...
- Linux Shell程序设计(2)
实验十一.Shell程序设计(2) 一.实验要求 综合运用shell编程知识进行设计性编程. 二.实验内容和实验步骤 1.[实验内容] 假设你作为某工厂生产管理员,需要负责统计各车间每天生产的产品数据 ...
- 【Linux学习笔记④】——Shell程序设计【变量 输入与输出 条件表达式 判断语句 循环语句 Shell函数】
⌛️ 文章目录 一.Shell 概述 二.Shell 脚本的定义与执行 2.1 Shell 脚本的定义 2.2 Shell 脚本的执行 三.Shell 变量 3.1 用户自定义变量 3.2 环境变量 ...
- Linux操作系统笔记——Shell程序设计
目录 一.Shell脚本的概念 二.一个Shell脚本的基本步骤 三.赋予Shell脚本执行权限 (一)Shell调用脚本 (二)chmod命令赋予脚本执行权限 四.Shell功能性语句 (一)rea ...
最新文章
- PHP-7.1 源代码学习:虚拟机字节码
- 黑猫315十大行业乱象发布:背后真假套路难辨
- ubuntu14.04禁用USB外存储设备
- SPOJ 375 query on a tree 树链剖分
- linux系统如何启用ftp服务
- tp5 使用PHPAnalysis提取关键字中文分词
- linux 小度 驱动_Linux硬链接和软链接
- Spring、Ibatis结合MySQL数据库的使用方法
- DPDK之PMD原理
- C#:使用dsoframer.ocx控件实现内嵌office效果(详解)
- 全球最强免费电子书下载网址
- scan camera
- 手机邮箱怎么弄_如何设置Android手机邮箱的详细教程
- Java数据结构项目
- 手游后劲不足,“体验”会是端游发展的一张王牌吗?
- 短视频SDK接入(2)---环境搭建
- java.lang.IllegalArgumentException 如何解决这个异常
- “麒麟计划”落地苍南,赋能外贸企业数字化转型!
- matlab 判断是否执行完毕,server酱_代码执行结束推送到微信_matlab和python
- 新版本idea shit+shit存在搜索历史记录
热门文章
- java jinternalframe_JInternalFrame的使用
- rabbitmq怎么停止_rabbitmq 启动与停止
- import caffe ImportError: No module named 'skimage'
- java中什么是守护线程_什么是Java的守护线程?
- OSG的垃圾回收机制
- mailcore(一)
- c语言中的数组覆盖,[求助] 怎么得到被覆盖的数组?
- php 实现同一个账号同时只能一个人登录
- 核心技术靠化缘是要不来的——自己动手写ORM框架
- DataTabel中关于ImpotRow的一点尝试