实验二 Linux shell程序设计总结_实验二shell编程
实验二 Linux shell程序设计总结由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“实验二shell编程”。
实验二 Linux shell程序设计
一、实验目的熟悉linux shell 简单程序设计
二、实验内容
1、变量引用。在用户主目录下运行如下命令
$dir_1=/11/22 $echo $dir_1 $echo dir_1
2、数组。在用户主目录下运行如下命令
$city[0]=Beijing $city[1]=Shanghai $city[2]=Tianjin
显示city的第二个元素的值
$A=(this is an example of shell script)(1)同时显示数组A的第2、4、6个元素的值。(2)显示所有数组元素的值
3、完成书上P106-107中关于read命令的使用的例子。
4、完成书上p108-110例4.7-例4.9
三、实验步骤
1.输入命令:
$dir_1=/11/22 $echo $dir_1 $echo dir_1
2.输入命令:
$city[0]=Beijing $city[1]=Shanghai $city[2]=Tianjin $echo ${city[2]} $A=(this is an example of shell script)$echo ${A[2]} ${A[4]} ${A[6]} $echo ${A[8]} 3.输入命令:
$read x y z Today is Monday $echo $z $x $y $read n1 n2 n3 First Second Third 1234 abcd $echo $n3 $echo $n2 $n1 Read n1 n2 n3 1 2 $echo $n3 $echo $n1 $n2
4.4-7:$touch m1.c
$vi m1.c
按”i”输入:main()
{
printf(“Beginn”);
}
按“Esc”输入“:wq”
$cat m1.c
$touch m2.c
$vi m2.c
按”i”输入:main()
{
printf(“OK!n”);
printf(“Endn”);
}
按“Esc”输入“:wq”
$cat m2.c $touch ex6
$vi ex6 按”i”输入:#ex6:shell script to combine files and count lines
cat $1 $2 $3 $4 $5b $6 $7 $8 $9|wc –l
#end
按“Esc”输入“:wq”
$cat ex6 $chmod a+x ex6 $PATH=$PATH:.$ex6 m1.c m2.c
4-8 $touch ex7 Vi ex7 i #!/bin/bash #ex7:shell script to combine filesand count lines #using command set to set positional paramters Set m1.c m2.c Cat $1 $2 $3|wc-l #end $cat ex7 $chmod a+x ex7 $PATH=$PATH:.$ex7
4-9 $touch ex8 Vi ex8 i
#!/bin/bash
#ex8:shell script to demonstrate the shift command Echo $0 $ 1 $2 $3 $4 $5 $6 $7 $8 $8 &9 Shift Echo $0 $ 1 $2 $3 $4 $5 $6 $7 $8 $8 &9 ShiftEcho $0 $ 1 $2 $3 $4 $5 $6 $7 $8 $8 &9 #end $cat ex8 $chmod a+x ex8 $PATH=$PATH:.$ ex8
四、实验总结
通过这次实验,我懂得了定义SHELL程序设计中的变量,掌握了SHELL程序中LINUX基本命令的使用,理解了SHELL程序的设计方法,并且熟悉了SHELL程序编辑、运行、调试方法与过程。这位我日后继续深入学习LINUX课程打下基础。