实验六

作者: 西寻 | 来源:发表于2015-11-08 21:38 被阅读26次

    实验六 编辑Linux脚本程序

    实验目的

    1.熟悉简单的Linux脚本程序的结构与原理

    2.掌握编写脚本程序的方法与步骤

    3.学会编写并运行简单脚本程序

    实验环境

    ubuntu 14.04 LTS

    实验内容

    1.编写简单的脚本程序

    a.用Vim命令新建名为"test.sh"的脚本程序文件

    6003@go:~$ vim test.sh

    b.编辑程序并保存退出

    如下为显示"Hello World"的程序的编写

    截图10.png

    c.为程序添加用户权限

    6003@go:~$ chmod 755 test.sh

    d.运行测试锁边机的脚本程序

    6003@go:~$ ./test.sh

    如下为测试结果

    6003@go:~$ vim testsh.sh

    6003@go:~$ vim test.sh

    6003@go:~$ chmod 755 test.sh

    6003@go:~$ ./test.sh

    ‘Hello World!’

    2.一些简单脚本程序的输出展示

    a.显示用户输入年龄的年龄范围

    6003@go:~$ vim test02.sh

    6003@go:~$ chmod 755 test02.sh

    6003@go:~$ ./test02.sh

    Please enter your age:

    21

    You are in your 20s

    6003@go:~$ ./test02.sh

    Please enter your age:

    90

    Sorry, you are out of the age range.

    b.特定输入的反应输出命令

    6003@go:~$ vim test03.sh

    6003@go:~$ chmod 755 test03.sh

    6003@go:~$ ./test03.sh

    Please enter a letter:

    A

    You have typed a vowel!

    6003@go:~$ ./test03.sh

    Please enter a letter:

    c

    You have typed a consonant!

    c.循环算数命令

    6003@go:~$ vim test04.sh

    6003@go:~$ chmod 755 test04.sh

    6003@go:~$ ./test04.sh

    Enter the number

    1

    The factorial of 1 is 1

    6003@go:~$ ./test04.sh

    Enter the number

    3

    The factorial of 3 is 6

    6003@go:~$ ./test04.sh

    Enter the number

    16

    The factorial of 16 is 20922789888000

    实验小结

    1.利用Vim编辑器编辑脚本程序时需注意格式要求。

    2.编写Linux脚本程序需要注意添加权限,并能使程序符合系统要求。

    3.可以在不同操作端上编写程序命令,并在系统源文件下运行命令。

    相关文章

      网友评论

          本文标题:实验六

          本文链接:https://www.haomeiwen.com/subject/kvochttx.html