操作系统实验报告1

更新时间:2023-04-07 14:46:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

操作系统实验报告 1

《计算机操作系统》实验报告实验题目:进程控制

姓名:学号:实验日期:

SHELL编程实验:

实验目的:

掌握vi的三种工作方式,熟悉vi编辑程序的使用。

学习Shell程序设计方法。掌握编程要领。

实验内容:

学习使用vi编辑程序。

编写Shell程序。

将程序文件设置为可执行文件(用chm od命令)。

在命令行方式中运行Shell程序。

操作过程:

操作系统实验报告 1

用vi编写第四部分“ Shell程序设计”中的例1 (假设文件名为myprogl.h)

操作系统实验报告 1

Kieuqa>i ocainosr

File Edit View Tferminai [kieu@loc atho st ~]$ vi my p ro g L .h

[kleu^loc alho st —]i c at myp rog1,h #Name display p rog ram

IT [ $# = O ]

then

ec ho * Name not P rovided"

eVse

echo " You r name 1 s *' $L

fl

[kieu@loc atho st ~]$ ./myp rog L . h Th eodo re

You r name a s Theodo re

[kieu^localhost ~]车 ■

进一步修改例1程序,要求显示参数个数,程序名字,并逐个显 示参数。

[kieu^Localhost —]事 vi myp rog L .h [kieu @Loc alh os t —]$ c at myp rog L.h #1Mame di splay p rog ram if [车# = o ] then echo " You r shell p rog ram name 1 s *' $o et se ec ho " You r pa ramete r nu mbe r is 11 勒# T± [kieu@Toc^lh ost 一]车./myp rog 1,h You r sheXL p rog ram n ame 1s ./myp rog L ? h [kieu @Localhost ~]乍 ./myp r o g1,h kieu d i en You r pa ramete r nuimbe r is 2 [kieu @l_oc aThost ~]峯■

修改例1程序,用read 命令接受键盘输入。若没输入字符显示第 一种显示,否则第二中显示。 [kieu@locathost ~]$ [kieu^loc aLho st —]t Name nor P

rovided

c hmo

d 755 myp rog L. h ./myp

rog L.h

操作系统实验报告 1

用vi编写第四部分“ Shell程序设计”中的例2 (假设文件名为st.h ),例3 (假设文件名为compare2.h)

read ch

if

【th

en

-z tch 1

else

echo "Name not provided

fi

echo "You r name is " $th

[kieu^localhost ./myp rogl.h kieu

You r name is kieu

[kied^localhos t “]$ ./myp rogLh

Name not provided

[kieu^localhost T* |

[kieu^localhost ~]f vi mypr ogl.h

[kieu^localhost ~ji cat myp roql,h #Name

display p rog ram

操作系统实验报告 1

.. oca lh OS

file £dit 里 iew Jerminal F|elp

then echo 11 cppdi r has execute pe rmi ssione"

el se

echo "cppdi r does not have execute pe rmissione f i

f kjeu@loc alhost t -/compa re2.h

c ppdi r i s a di rec to ry

filea 1s a regula r file

filea has read pe rmissione

filea dose not have wriet pe rmissione

cppdi r h a5 exec u te pe rmissione

修改例2 (假设文件名为st.h )程序使在程序运行中能随机输入 字符串,然后进行字符串比较

echo "st ring 1 not

equal to st ring2H fi

■if [ t ring L ]

then echo " st ring 1 i s else not emp 七y" echo "st ring 1 is f i if ( - n st nng2 )

empty

亡亡ho "st ring2 has el se

a length g reate r than ze ro echo " s t irzng2 has f i a length equal to zero 11

[kleu@l DC alhost ~]$ ./st kieu kieu h

st ringl equ al to st ring2 st ringl is not empty el se

st ring2 has a length g reate r th an ze ro [kj.eu01ocalhost -11 II el &e fi

if [ the n

else fi if ( the echo "filea

has read permissione" echo "f ilea dose

rot have read pe rmisaione" w filea ] echo ■fil ea has 1 w rite pe rmi ssione" echo "files

dose not have wriet pe rmis sione p x 匚ppdi r ]

[kzeu^localhost -]慕 cat st . h read strlngl read st ring2 if [ tst ring 1 = $st ring2 ] then echo "st ring L equal to s t ring2-

操作系统实验报告 1

修改例3 (假设文件名为compare2.h )程序使在程序运行中能随 机输入文件名,然后进行文件属性判断。

[kieu^localhost ~]t cat compare2 + h read filename

if [ -f filename ]

then echo iLename " is a reguLar file n el se

echo tfilename " ia not a regula r file'1 f i

if [ -r filename ]

then

has read pe rmissione" dose not have read pe rmissione* has write pe rmi5sione " dose not have wriet permissione

[kieu^tocalhost ~]t ./compa re2 r h st . h

st.h 1s a regula r file

st > h has read pe rmissione

st .h has write pe rmissione

[kieu^localhost |

用vi 编写第四部分“ Shell 程序设计”中的例9 (假设文件名为 fun ) echo tfiLename eL

se

echo ILename f i if [ -w filename ] then

echo tfilename

el se

echo liename fl

-rwx r- x r- x . d rwx r- x r- x. d rwx r- x r- x . L kieu 2 kieu 2 kieu kieu 341 kieu 4096 kieu 4096 2009-11-04 2G09-1G-3L 2G09 ?1G ■3L 12: G6 17: 25 reaplates 17:25 Videos

操作系统实验报告 1

区' kieu^lccalhost :^ 命 File Edit View Jerminal 旦 elp [kieu^localhast T$ cat fun.h

displaymon th (){ case in

01

02

esac

}

displaymonth 8 displaymanth 12

[kieu@local.hosr . /fun . h month is Augu st mon th is Decembe r

[kieu@l_ocal.h0st | 编程,在屏幕上显示用户主目录名(HOM )命令搜索路径(PATH , 并显示由置参数指定的文件的类型和操作权限。

结果:

叫 试一试vi 的三种工作方式个用在什么时候?用什么命令进入 插入方

式?怎么退出插入方式?文件怎么存盘注意存盘后的 提示信息。

基本上vi 可以分为三种状态,分别是命令模式(comma nd

mode 、插入模式(In sert mode 和未行模式(last li ne mode , 各模式的功能区分如下:1) echo "month is Janua ry ";,

2) echo "man th is Februa ry";;

3) echo "month is Ma rc h ";;

4)

echo "month is Ap riV"::

5) echo "month is May";;

6) echo "month is June"\ \

7) echo "month is July";;

3) echo "month is August "* *

9} echo "month is Scptembe r";; 11) echo "month is November";; 012

12) echo "month is December";; *) echo

"Invalid parameteL ;;

10) echo "month is October";;

345678911

操作系统实验报告 1

1)命令行模式command mod)e :控制屏幕光标的移动,

字符、字或行的删除,移动复制某区段及进入Insert mode下, 或者到last line mode 。

2)插入模式( Insert mode ) :只有在Insert mode 下,才

可以做文字输入,按「ESC键可回到命令行模式。

3)未行模式( last line mode) :将文件保存或退出vi ,

也可以设置编辑环境,如寻找字符串、列出行号……等。

不过一般我们在使用时把vi 简化成两个模式,就是将未行模式( last line mode )也算入命令行模式command mod)e 。

体会:

熟悉了vi 三种工作方式,学会了创建和执行shell 程序。

本文来源:https://www.bwwdw.com/article/ortl.html

Top