1、 目 录 摘 要. 1 前言 2 1 绪论 3 1.1 Shell 的定义. 3 1.1.1 UNIX Shell. 3 1.2 shell 的历史. 4 1.3 shell 的职责. 4 2 开发环境和开发工具介绍 . 6 2.1 开发环境-Ubuntu. 6 2.2 开发工具-GCC. 6 3 模拟 shell 设计 7 3.1 简单 shell 设计思想. 7 3.2 复杂 shell 设计思想. 8 3.2.1 作业及作业前后调度实现方法. 8 3.2.2 进程组、会话与终端 . 9 3.2.3 命令行 10 3.2.4 、bg、fg 等信号的思想 . 10 3.2.5 管道 11 3
2、.2.6 重定向 11 4 Shell 的实现 13 4.1 数据结构 13 4.2 程序结构 13 4.2.1 初始化环境 13 4.2.2 解析命令 14 4.2.3 查找外部程序 15 4.2.4 执行命令 16 4.2.5 管道 17 4.2.6 作业控制命令 18 5 结束语 . 20 致谢 21 参考文献 . 22 附录 23 1 LinuxLinux 命令解释器的设计命令解释器的设计 摘摘 要要:随着 Linux 系统使用的越来越广泛,越来越多的人开始深入的研究 Linux,特别是对 Linux shell 的研究是对 Linux 研究最主要的部分。本文主要 是研究了对 shel
3、l 的功能的一些认识,而且对 shell 的列表,管道,输入重定向 和输出重定向等命令功能进行了实现, 可以对 shell 命令解释器进行更加全面的 认识和充分的了解,而且在 shell 命令解释器中执行正确的命令,从而对它的原 理,方法等在程序中必须用到的知识原理有比较清楚的认识,最后通过对每个功 能的详细分析,进而编写出恰当实现各个功能的代码,从而做成一个 Shell 命令 解释器。 并且,在嵌入式领域中,与人们的需求相比,硬件的资源是微不足道的。这 就意味着我们把不多的资源利用完成很多的需求,而嵌入式的设计在 PC 上编程 是有很大不同的, 它其实只需要一个很大程序的比较小的一方面就可以
4、满足它的 需求,因此我们必须把一些无用的程序删掉来换成空间。在嵌入式领域中就像传 统的 K shell,C shell,Bourne shell 等大型的 shell 程序就会令硬件方面的 东西很少。因此我们需要一个更符合嵌入式系统中使用的 Shell。 关键词:关键词:Shell;程序;设计与实现;嵌入式;Linux Abstract:Accompanied by the popularize of the Linux,more and more people are doing deeply study in it.The study of shell is the most import
5、ant thing when study the Linux.It mainly includes the understand of some knowledge and function of the micro linux shell.Through the study of the orders in the shell like list,pipe,input redirect and output redirect,readers can have a thorough sense about the shell and learn to use these orders accu
6、rately in shell which play an important role in programming later.Code accurately and achieve a simple shell with the functions above after analyzing the details of every functions module. Moreover,in the embedded field,the hardware resources are limited,but demand is unlimited.This means they have to use limited resources to accomplish a variety of needs and embedded design and programming in the traditional PC,is very different ,and it often requires only a small part of a large program