Linux实验11shell程序设计,Linux实验报告(实验四)shell编程实验

41528d3028836879cd698677c3999917.gifLinux实验报告(实验四)shell编程实验

实验四 shell 编程实验(二)班级: 姓名: 学号: 上机时间:年 月 日任课教师: 实验教师: 实验成绩: 一、实验目的综合 Linux 常用命令和 vi 编辑器的使用,熟练掌握 shell 脚本编程。二、实验注意事项实验室内的实验环境与系统是共用设施,请不要在系统内做对系统或对其他用户不安全的事情。要求每个同学登录后系统后,要在自己的家目录下创建一个属于自己的子目录(以自己(拼音)名字或学号) 。以后所有工作都要在自己的目录内进行。建议以后的实验都在同台计算机上做,这样可以保持连续性。三、实验内容1. 编写一个脚本,求斐波那契数列的前 10 项及总和。num1=1num2=1echo -n “$num1+$num2”sum=2for((i=1;i<=8;i++))dotmp=$(expr $num1 + $num2)echo -n “+$tmp”((num1=num2))((num2=tmp))sum=$(expr $sum + $tmp)doneecho “=$sum”2.编写一个脚本,求一个数的逆序。echo -n please num:read numecho -n The num is while [ $num -gt 0 ]dosd=$(($num % 10))echo -n “$sd“num=$(($num/10))doneecho3.设计一个 Shell 程序,在用户主目录下建立一个 userdata 目录,在此目录下再建立 5 个目录,即 user1~user5 ,并设置每个目录的权限,其中其他用户的权限为:读;文件所有者的权限为:读、写、执行;文件所有者所在组的权限为:读、执行。 (注意:最后删除自己所建立的目录,恢复原样,以便后面同学做此实验)mkdir -m 754 /home/userdatai=1temp=/home/userdata/userwhile[ $i -le 5 ]domkdir -m 754 $temp$ilet”i=i+1”#done4.用 Shell 编程,判断一文件是不是普通文件,如果是将其拷贝到 /home/student/test 目录下,用命令查看 test 目录内容,最后再删除 test 目录。mkdir -m 777 /home/testecho “ file name:”read FILENAMEif [ -f “$FILENAME” ]thencp $FILENAME /home/testls /home/testcd testrm $FILENAMEcd .lselseecho”The FILENAME is not a regular file!”fi5.编程实现简单计算器。要求 用户输入一个表达式并输入结果,程序会判断用户输入的结果是否正确,并给出提示。直到 用户输入‘q’时,才退出执行。参考程序:#!/bin/bash#fileName:first#note:This is the first title#function: an expretion and the answer, I will tell you right or wrong# You can try it as many times as you like.echo Hello! @_@ echo Welcom to the calculate testing!echo You can an expretion such as 2*2 or 3+1, and the answerecho I will tell you whether you are right or wrong.echo You can q to exit.echo “Now let s begin!“number1=0;while [ “$number1“ != “q“ ] do echo the first number:read number1echo the operator type:read typeecho the second number:read number2 echo the answer:read yourAnswercase $type in+) myAnswer=`expr $number1 + $number2`;;-) myAnswer=`expr $number1 - $number2`;; \*)myAnswer=`expr $number1 \* $number2`;;/) if [ $number2 -eq 0 ]thenecho “Sorry! :-(“echo “0 cannot be the divisor“continue elsemyAnswer=`expr $number1 / $number2`fi;;*) echo Error!;;esacif [ $myAnswer -eq $yourAnswer ]then echo “:-)“ Congratulations!echo Your are right!echo q to exit or try again!elseecho “:-(“ Sorry!echo You are wrong!echo “The right answer is:“echo “$number1 $type $number2 = $myAnswer“echo q to exit or try again! fi# echo the first number:# read number1done要求:请同学仔细分析该程序,理解其中的语句及用法,写出程序分析及总结。总结:四、实验报告要求1.列出调试通过程序的清单,并加注释。2. 写出程序运行步骤及结果。3.总结上机调试过程中所遇到的问题和解决方法及感想。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值