Shell是一些特定的程序接口,用于用戶和UNIX/Linux操作系統(tǒng)核交互。如下圖所示:
1.Unix Shell
(1) Bourne shell (
sh)是標準的UNIX shell, 用于管理系統(tǒng). 很多系統(tǒng)管理的腳本。例如
rc start和stop腳本以及shutdown 是Bourne shell 腳本;缺省的Bourne shell 表示為(
$)
(2) C shell (
csh)是伯克利開發(fā)的,增加了很多新的特征, 例如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)建立可執(zhí)行程序
3.Shell命令執(zhí)行圖:

4.系統(tǒng)啟動和登錄Shell
啟動系統(tǒng)->>調(diào)用
init->>分配PID=1->>打開終端線->>建立
stdin,
stdout和stderr->>輸入login name,->>輸入password->>
/bin/login通過
passwd文件驗證你的密碼.如果
login驗證成功,則會開始建立初始環(huán)境
HOME,
SHELL,
USER, 和
LOGNAME 是從
passwd中抽取的變量值.
HOME變量指定你的home目錄,
SHELL指定登錄shell的名稱,它是passwd文件的最后一個入口.
USER 和
LOGNAME 變量指定你的登錄名. ->>執(zhí)行passwd文件中的最后一個入口程序
. 通常這個程序就是shell. 如果
passwd文件中的最后一個程序是
/bin/csh, C shell被執(zhí)行,如果是
/bin/bash 或者null, Bash shell執(zhí)行. 如果是
/bin/ksh 或者
/bin/pdksh, Korn shell 被執(zhí)行. ->>檢查系統(tǒng)初始化文件建立->>檢查登錄目錄下的初始化文件. ->>等待用戶輸入。
4.1解析命令行的過程:
(1)執(zhí)行歷史記錄替換
(2)命名行被分割成符合或者字
(3)更新歷史記錄
(4)處理引用
(5)別名替換和定義函數(shù)
(6)建立重定向,后臺和管道
(7)執(zhí)行變量(
$user,
$name, etc.) 替換
(8)執(zhí)行命令替換
(9)文件名替換,調(diào)用
globbing (
cat abc.??,
rm *.c, etc.)
(10)執(zhí)行命令
4.2命令的類型
(1)別名
(2)關(guān)鍵字
(3)函數(shù)
(4)內(nèi)建命令
(5)可執(zhí)行命令
5.進程和Shell
5.1查看進程
$
ps aux (BSD/Linux ps) (use ps -ef for SVR4)
$ pstree
6.環(huán)境和繼承
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
一葉笑天 閱讀(627)
評論(0) 編輯 收藏 所屬分類:
Shell技術(shù)