一叶笑天
雄关漫道真如铁, 而今迈步从头越。 从头越, 苍山如海, 残阳如血。
posts - 73,comments - 7,trackbacks - 0
Shell是一些特定的程序接口,用于用户和UNIX/Linux操作系统核交互。如下图所示:
1.Unix Shell
  (1) Bourne shell (sh)是标准的UNIX shell, 用于管理系统. 很多系统管理的脚本。例如rc start和stop脚本以及shutdown 是Bourne shell 脚本;缺省的Bourne shell 表示为($)
  (2) C shell (csh)是伯克利开发的,增加了很多新的特征, 例如command-line history, aliasing, built-in arithmetic, filename completion, and job control. Bourne shell 脚本快于和简单于C shell. 缺省C shell 表示为(%)
  (3) Korn shell是Bourne shell的超集. Korn shell 增强的特征有editable history, aliases, functions, regular expression wildcards, built-in arithmetic, job control, coprocessing, and special debugging features. Bourne shell is 完全向上兼容Korn shell,q缺省的Korn shell提示符是 ($)
2.Shell的职责是:
(1)读入输入和解析命令行
(2)计算特殊字符,例如wildcards和历史字符
(3)建立管道,重定向和后台处理
(4)处理信号
(5)建立可执行程序
3.Shell命令执行图:

4.系统启动和登录Shell
启动系统->>调用init->>分配PID=1->>打开终端线->>建立stdin,stdout和stderr->>输入login name,->>输入password->> /bin/login通过passwd文件验证你的密码.如果login验证成功,则会开始建立初始环境 HOME, SHELL, USER, 和 LOGNAME 是从passwd中抽取的变量值. HOME变量指定你的home目录, SHELL指定登录shell的名称,它是passwd文件的最后一个入口. USER 和 LOGNAME 变量指定你的登录名. ->>执行passwd文件中的最后一个入口程序. 通常这个程序就是shell. 如果passwd文件中的最后一个程序是 /bin/csh, C shell被执行,如果是 /bin/bash 或者null, Bash shell执行. 如果是 /bin/ksh 或者 /bin/pdksh, Korn shell 被执行. ->>检查系统初始化文件建立->>检查登录目录下的初始化文件. ->>等待用户输入。
4.1解析命令行的过程:
(1)执行历史记录替换
(2)命名行被分割成符合或者字
(3)更新历史记录
(4)处理引用
(5)别名替换和定义函数
(6)建立重定向,后台和管道
(7)执行变量($user, $name, etc.) 替换
(8)执行命令替换
(9)文件名替换,调用globbing (cat abc.??, rm *.c, etc.)
(10)执行命令
4.2命令的类型
(1)别名
(2)关键字
(3)函数
(4)内建命令
(5)可执行命令
5.进程和Shell
5.1查看进程
$ ps aux  (BSD/Linux ps)  (use ps -ef for SVR4)
$ pstree
6.环境和继承
1   $ id
   uid=502(ellie) gid=502(ellie)
查看用户的标识user identification (UID), group identifications (GID),
6.3修改文件许可
chmod
Permission Modes

Decimal

Binary

Permissions

0

000

none

1

001

--x

2

010

-w-

3

011

-wx

4

100

r--

5

101

r-x

6

110

rw-

7

111

rwx

chmod is as follows: r = read; w = write; x = execute; u = user; g = group; o = others; a = all.
1   $ chmod 755 file
    $ ls –l file
    –rwxr–xr–x 1 ellie  0 Mar  7 12:52 file
2   $ chmod g+w file
    $ ls -l file
    –rwxrwxr-x  1 ellie  0 Mar 7 12:54 file
3   $ chmod go-rx file
    $ ls -l file
    –rwx-w---- 1 ellie  0 Mar 7 12:56 file
4   $ chmod a=r file
    $ ls -l file
    –r--r--r-- 1 ellie  0 Mar 7 12:59 file
chown改变文件和目录的所有属性
1   $ ls -l filetest
    -rw-rw-r--   1 ellie    ellie           0 Jan 10 12:19 filetest
6.4工作目录
1   > cd /
2   > pwd
    /
3   > bash
4   $ cd /home
5   $ pwd
    /home
6   $ exit
7   > pwd
    /
    >
6.5查看变量
$ env
6.6重定向和管道
重定向
1   $ who > file
2   $ cat file1 file2 >> file3
3   $ mail tom < file
4   $ find / -name file -print 2> errors
5   % ( find / -name file -print > /dev/tty) >& errors
管道
|
who | wc
6.7Shell和信号
标准信号

Number

Name

Description

Action

0

EXIT

Shell exits

Termination

1

SIGHUP

Terminal has disconnected

Termination

2

SIGINT

User presses Ctrl-C

Termination

3

SIGQUIT

User presses Ctrl-\

Termination

4

SIGILL

Illegal hardware instruction

Program error

5

SIGTRAP

Produced by debugger

Program error

8

SIGFPE

Arithmetic error; e.g., division by zero

Program error

9

SIGKILL

Cannot be caught or ignored

Termination


posted on 2008-06-18 10:37 一叶笑天 阅读(609) 评论(0)  编辑  收藏 所属分类: Shell技术

只有注册用户登录后才能发表评论。


网站导航: