linux3
- 格式:doc
- 大小:42.50 KB
- 文档页数:3
南京信息工程大学 滨江学院 实验(实习)报告
实验(实习)名称 常用命令使用 实验(实习)日期 指导教师
专业 年级 班次 姓名 学号得分
一.实验目的
1. 了解shell的作用和主要分类。
2. 掌握bash的建立和执行方式。
3. 掌握bash的基本语法。
4. 学会编写shell脚本。
二.实验内容
1. shell脚本的建立和执行。
2. 历史命令和别名定义。
3. shell变量和位置参数、环境变量。
4. bash的特殊字符。
5. 一般控制结构。
6. 算术运算及bash函数。
三.主要实验步骤
1. 利用vi建立一个脚本文件,其中包括date,cal,pwd,ls等常用命令。然后以不同方式执行该脚本。
方式一:
[LinyunGu@local host subdir]$ vi comand
[LinyunGu@local host subdir]$ ls
comand file file1 file10 file5 file.c
[LinyunGu@local host subdir]$ chmod +x comand
[LinyunGu@local host subdir]$ ls
comand file file1 file10 file5 file.c
[LinyunGu@local host subdir]$ ./comand
五月 2011
日 一 二 三 四 五 六
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
/home/LinyunGu/subdir
comand file file1 file10 file5 file.c
方式二:
[LinyunGu@local host subdir]$ bash 2011年05月 22日 星期日 16:36:13 CST 五月 2011 日 一 二 三 四 五 六 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 /home/LinyunGu/subdir comand file file1 file10 file5 file.c 方式三: [LinyunGu@local host subdir]$ PATH=SPATH:. [LinyunGu@local host subdir]$ comand 2011年05月 22日 星期日 16:36:13 CST 五月 2011 日 一 二 三 四 五 六 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 /home/LinyunGu/subdir comand file file1 file10 file5 file.c 2. 运行history命令,配置历史环境。 129 command 130 ls 131 comand 132 PATH=SPATH:. 133 comand 134 history 配置历史环境:$HISTORY=“ 历史环境路径” 3. 体会bash的命令补齐功能。 如果所选的文件或目录存在,只需要打少量字符 按下tab键便可以显示全部文件或目录名 4. 用alias定义别名,然后执行。 [LinyunGu@local host subdir]$ alias tt='ls -1' [LinyunGu@local host subdir]$ tt 总计60 -rw-rw-r-- 1 LinyunGu LinyunGu 28 05-22 21:51 comand -rw-rw-r-- l LinyunGu LinyunGu 5862 05-22 19:15 file -rw-rw-r-- 2 LinyunGu LinyunGu 5747 05-22 16:59 file1 -rw-rw-r-- l LinyunGu LinyunGu 5704 05-22 19:20 file10 -rw-rw-r-- 1 LinyunGu LinyunGu 778 05-22 17:33 file5 -rw-rw-r-- l LinyunGu LinyunGu 573 05-22 19:15 file.c 5. 对思考题4.8进行编辑,然后执行。 [LinyunGu@local host subdir]$ ./gg.sh 5 5 5-1 5-1-1 5-1-1-1 5-1-1-1-1 6. 对思考题4.14进行编辑,然后执行。 运行结果如下: [LinyunGu@local host subdir]$ ./gg.sh 1 1 2 3 5 8 13 21 34 55 7. 对思考题4.18进行编辑,然后执行。 [LinyunGu@local host subdir]$ cuts 6 12 this is a test of cuts program is a te 8. 运行例4.20.如取消其中的eval,会出现什么情况? 下图为没有删除“eval”之前的结果: [LinyunGu@local host subdir]$ ./ex20.sh Enter a character:a You entered a Strike any key to continue...b 下图为删除“eval”之后的结果: [LinyunGu@local host subdir]$ ./ex20.sh Enter a character:a You entered Strike any key to continue...b 实验总结