堅持知識分享,該文章由Alopex編著, 轉載請註明源地址: http://www.cnblogs.com/alopex/ 索引: 什麼是shell shell的分類 shell腳本的執行方式 摘要: 瞭解shell的本質是什麼 瞭解除bash這個shell之外,還有哪些shell shell 腳本 ...
堅持知識分享,該文章由Alopex編著, 轉載請註明源地址: http://www.cnblogs.com/alopex/ 索引:
- 什麼是shell
- shell的分類
- shell腳本的執行方式
- 瞭解shell的本質是什麼
- 瞭解除bash這個shell之外,還有哪些shell
- shell 腳本以及shell腳本的執行方式/區別

什麼是shell 一般來說,操作系統由用戶介面(User Interface)和系統內核(kernel)兩部分構成 從名字可以看出,內核是操作系統的核心, 它是一個操作系統的靈魂 內核的主要作用有以下幾點
- 文件管理 (File manager) 協調調度電腦中的大容量存儲
- 設備驅動 (Device drivers) 使接入電腦的周邊設備能相互通信
- 記憶體管理 (Memory manager) 協調調度電腦中的記憶體
- 進程調度 (Scheduler) 協調調度系統中的進程
- 時間調度 (Dispatcher) 給予進程CPU的使用時間
- 系統調用 (System calls) 進程請求系統內核去執行一些它(普通進程)沒有許可權執行的命令
- 簡單概括, 內核負責管理電腦硬體資源(CPU, 記憶體, 硬碟, 周邊設備I/O)的使用
- 簡單地概括, shell 本質應該是CLI, 它是一個讓用戶通過命令行來實現和系統交互的介面.
shell的分類 操作系統: CentOS release 6.9 (Final) 命令提示符 PS1 : \[\e[31m\]>\[\e[m\] (下圖中紅色的> 為命令提示符) 來介紹shell的分類之前, 先來介紹一下關於shell查看的幾個常用操作 查看系統預設的shell



2014年9月, bash曾曝出一個嚴重的漏洞CVE-2014-6271
ShellShock Bug (特製環境變數註入攻擊) 我們使用以下命令對系統進行測試 env x='() { :;}; echo vulnerable' bash -c "echo this is a test"


Features of the Bourne shell versions since 1979 include:
- Built-in
test
command – System III shell (1981) - # as comment character – System III shell (1981)
- Colon in parameter substitutions "${parameter:=word}" – System III shell (1981)
continue
with argument – System III shell (1981)cat <<-EOF
for indented here documents – System III shell (1981)- Functions and the
return
builtin – SVR2 shell (1984) - Built-ins
unset
,echo
,type
– SVR2 shell (1984) - Source code de-ALGOL68-ized – SVR2 shell (1984)
- Modern "
$@
" – SVR3 shell (1986) - Built-in
getopts
– SVR3 shell (1986) - Cleaned up parameter handling allows recursively callable functions – SVR3 shell (1986)
- 8-bit clean – SVR3 shell (1986)
- Job control – SVR4 shell (1989)
- Multi-byte support – SVR4 shell (1989)
- Job control, command aliasing, and command history designed after the corresponding C shell features. Job control was added to the Bourne Shell in 1989.
- A choice of three command line editing styles based on vi, Emacs, and XEmacs.
- Associative arrays and built-in floating point arithmeticoperations (only available in the ksh93 version of KornShell).
- Dynamic extensibility of built-in commands (as of ksh93)

C Shell 家族有兩個成員 [csh, tcsh]
[csh] csh 其設計者是 Bill Joy 由於csh擁有交互的特性, 在1980年, csh以其易於上手的特性, 贏得了青睞 csh的設計理念是使得它開起來更像是 C語言, 並且擁有更好的用戶交互性
Bourne shell #!/bin/shif [ $days -gt 365 ]then echo This is over a year. fi |
C shell #!/bin/cshif ( $days > 365 ) then echo This is over a year. endif |
shell 腳本的執行方式

# 執行的腳本




[關於 子shell 和 父shell] 簡單來說,子shell和父shell的關係有以兩點 1.子shell 會複製 父shell的變數和函數, 就如同子女繼承父母的基因一樣, 2.子shell中設置的變數和函數只有子shell自己知道, 子shell無法改變父shell設定的變數和函數 腳本執行中, 如果使用 source / . 方式執行腳本, 命令會於當前shell中解析執行 下麵用一個簡單的腳本來體會一下, 當前shell中執行腳本, 和子shell執行腳本的取本 腳本內容


