Chinaunix首页 | 论坛 | 博客
  • 博客访问: 19726489
  • 博文数量: 679
  • 博客积分: 10495
  • 博客等级: 上将
  • 技术积分: 9308
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-18 10:51
文章分类

全部博文(679)

文章存档

2012年(5)

2011年(38)

2010年(86)

2009年(145)

2008年(170)

2007年(165)

2006年(89)

分类:

2006-12-08 09:32:49

1.1 定义和功能
shell 的作用:
(a) parse the command line;
(b) handle wildcards, redirection, pipes, and job control;
(c) search for the command, and if found, execute that command.

总之shell 用于解释命令,自定义用户环境,以及一种程序设计语言
  1. Reading input and parsing the command line.

  2. Evaluating special characters.

  3. Setting up pipes, redirection, and background processing.

  4. Handling signals.

  5. Setting up programs for execution.



自定义用户环境的功能如下:
These files contain definitions for setting terminal keys and window characteristics; setting variables that define the search path, permissions, prompts, and the terminal type; and setting variables that are required for specific applications such as windows, text-processing programs, and libraries for programming languages. The Korn shell and C shell also provide further customization with the addition of history and aliases, built-in variables set to protect the user from clobbering files or inadvertently logging out, and to notify the user when a job has completed.



3种主要的unix shell:
Bourne shell (AT&T shell), the C shell (Berkeley shell), and the Korn shell (superset of the Bourne shell).

Bourne shell:
用于管理系统,多数系统管理脚本用之书写, concise, compact, and fast.
the default Bourne shell prompt is the dollar sing($)

C shell
dded a number of features, such as command line history, aliasing, built-in arithmetic, filename completion, and job control.
交互性良好,but administrators prefer the Bourne shell for scripting, because Bourne shell scripts are simpler and faster than the same scripts written in C shell. The default C shell prompt is the percent sign (%).

The C shell is based on the C programming language, and when used as a programming language, it shares a similar syntax. It also offers enhancements for interactive use, such as command line history, aliases, and job control. Because the shell was designed on a large machine and a number of additional features were added, the C shell has a tendency to be slow on small machines and sluggish even on large machines when compared to the Bourne shell.

Korn shell
superset of the Bourne shell written by David Korn at AT&T.
A number of features were added to this shell above and beyond the enhancements of the C shell. Korn shell features include an editable history, aliases, functions, regular expression wildcards, built-in arithmetic, job control, coprocessing, and special debugging features. The Bourne shell is almost completely upward-compatible with the Korn shell, so older Bourne shell programs will run fine in this shell. The default Korn shell prompt is the dollar sign ($).

The Korn shell, really a superset of the Bourne shell, runs not only on UNIX systems, but also on OS/2, VMS, and DOS. It provides upward-compatibility with the Bourne shell, adds many of the popular features of the C shell, and is fast and efficient. The Korn shell has gone through a number of revisions. The most widely used version of the Korn shell is the 1988 version, although the 1993 version is gaining popularity. Linux users may find they are running the free version of the Korn shell, called The Public Domain Korn shell, or simply pdksh, a clone of David Korn's 1988 shell. It is free and portable and currently work is underway to make it fully compatible with its namesake, Korn shell, and to make it POSIX compliant. Also available is the Z shell (zsh), another Korn shell clone with TC shell features, written by Paul Falsted, and freely available at a number of Web sites.

The Linux Shells

Although often called "Linux" shells, Bash and TC shells are freely available and can be compiled on any UNIX system; in fact, the shells are now bundled with Solaris 8 and Sun's UNIX operating system. But when you install Linux, you will have access to the GNU shells and tools, and not the standard UNIX shells and tools. Although Linux supports a number of shells, the Bourne Again shell (bash) and the TC shell (tcsh) are by far the most popular. The Z shell is another Linux shell that incorporates a number of features from the Bourne Again shell, the TC shell, and the Korn shell. The Public Domain Korn shell (pdksh) a Korn shell clone, is also available, and for a fee you can get AT&T's Korn shell, not to mention a host of other unknown smaller shells.

but Linux Shell --bash have some improvements :
command line history and editing, directory stacks, job control, functions, aliases, arrays, integer arithmetic (in any base from 2 to 64), and Korn shell features, such as extended metacharacters, select loops for creating menus, the let command, etc.


The TC shell is an expanded version of the C shell. Some of the new features are: command line editing (emacs and vi), scrolling the history list, advanced filename, variable, and command completion, spelling correction, scheduling jobs, automatic locking and logout, time stamps in the history list, etc. It's also big.


1.2系统启动和登录的shell

The first process: init
The init process initializes the system and then starts another process to open terminal lines and set up the standard input (stdin), standard output (stdout), and standard error (stderr), which are all associated with the terminal.

The /bin/login program then verifies your identity by checking the first field in the passwd file

登录的以下流程暂略,参考鸟哥部分.

The order of processing the command line is as follows:

  1. History substitution is performed (if applicable).

  2. Command line is broken up into tokens, or words.

  3. History is updated (if applicable).

  4. Quotes are processed.

  5. Alias substitution and functions are defined (if applicable).

  6. Redirection, background, and pipes are set up.

  7. Variable substitution ($user, $name, etc.) is performed.

  8. Command substitution (echo for today is 'date') is performed.

  9. Filename substitution, called globbing (cat abc.??, rm *.c, etc.) is performed.

  10. Program execution.

Types of Commands

  1. Aliases

  2. Keywords

  3. Functions (bash)

  4. Built-in commands

  5. Executable programs

Aliases and functions are defined within the shell's memory. Built-in commands are internal routines in the shell, and executable programs reside on disk.




阅读(3513) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~