Linux实验报告二.doc

  1. 1、本文档共12页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Linux实验报告二

Linux程序设计实验二 实验目的: 熟练使用重定向,了解管道的作用 能够创建shell脚本,熟练进行变量赋值和引用,并了解环境变量和参数变量 shell编程中能够使用if语句,for语句,while语句和case语句,熟练使用条件判断语句 能够进行函数定义和调用 熟练使用echo,read,find,grep,return,exit,export,set命令 会调用命令输出结果 实验步骤: 重定向:在家目录下,将当前路径名称写入dirName.txt内;将当前目录下的详细信息写入content.txt内;使用date命令将当前时间写入date1.txt内,记录10条时间;删除一个不存在的文件,将错误信息写入rmErr.txt内。 你认为应使用的命令为: 1. 2. 3. 4. Shell脚本的创建和执行:创建一个bash shell脚本,完成以下功能:在任何文件夹下都可以输出“In A, there are B files at the time of C. Hi D, your home directory is E and the default paths include F”A显示当前文件夹名,B显示当前文件夹内容的数量,C显示当前时间, D显示当前用户名(提示:使用users和set命令,以及$1参数),E为家目录路径,F为默认程序路径 。 脚本内容为: #!/bin/sh A=$(pwd) B=`ls -al | grep ^[dlsbcp-] | wc -l` C=$(date) D=$(users) E=$HOME F=$PATH echo In $A, there are $B files at the time of $C.Hi $D, your home directory is $E and the default paths include $F exit 0 命令为: Shell中条件判断和循环语句的使用:创建shell脚本完成以下功能:提示连续输入2个字符串,字符串比对相符输出“Matched”,不符合输出“Not matched”,均结束程序。 脚本内容为: #!/bin/sh #提示输入两个字符串 echo Please input two strings,and separating them with blank character: echo 请输入两个字符串,并使用空格符隔开: read str1 str2 if [ $str1 = $str2 ] then echo Matched else echo Not Matched fi exit 0 Shell中条件判断和循环语句的使用:创建shell脚本完成以下功能:在一个文件中保存10个字符串,提示输入字符串,与10个已存字符串比对,符合执行ls命令,不符合执行sl命令。 脚本内容为: #!/bin/bash for count in `seq 10` do echo Pliease input No.$count string: read str tstr=`egrep $str test4` if [ $tstr = $str ] then ls else sl fi Done Shell中条件判断和循环语句的使用:创建shell脚本完成以下功能:提示输入月份+年份,返回这个月的日历(cal命令),并继续提示输入。 脚本内容为: #!/bin/sh mark=0 while [ $mark -eq 0 ] do echo Please input value of month and year with blank character,please input zero to month or year if you want to quit!\nmonth: read month if [ $month -le 0 ] then break fi echo year: read year if [ $year -gt 0 ] then cal $month $year else mark=1 fi done exit 0 Shell中条件判断和循环语句的使用:创建shell脚本完成以下功能:创建一个菜单,可以进行4个命令选择,可以模糊匹配,能够输出错误信息。 脚本内容为: #!/bin/sh echo Commands Content: echo command A: showordinaryfiles echo command B: showdirectoryfiles echo command C;sortfilesbysize echo command D:

文档评论(0)

xcs88858 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

版权声明书
用户编号:8130065136000003

1亿VIP精品文档

相关文档