詳見:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt189
Linux 中的 shell 有很多類型,其中最常用的幾種是: Bourne shell (sh)、C shell (csh) 和 Korn shell (ksh), 各有優缺點。Bourne shell 是 UNIX 最初使用的 shell,並且在每種 UNIX 上都可以使用, 在 shell 編程方面相當優秀,但在處理與用戶的交互方面做得不如其他幾種shell。Linux 操作系統缺省的 shell 是Bourne Again shell,它是 Bourne shell 的擴展,簡稱 Bash,與 Bourne shell 完全向后兼容,並且在Bourne shell 的基礎上增加、增強了很多特性。Bash放在/bin/bash中,它有許多特色,可以提供如命令補全、命令編輯和命令歷史表等功能,它還包含了很多 C shell 和 Korn shell 中的優點,有靈活和強大的編程接口,同時又有很友好的用戶界面。
GNU/Linux 操作系統中的 /bin/sh 本是 bash (Bourne-Again Shell) 的符號鏈接,但鑒於 bash 過於復雜,有人把 ash 從 NetBSD 移植到 Linux 並更名為 dash (Debian Almquist Shell),並建議將 /bin/sh 指向它,以獲得更快的腳本執行速度。Dash Shell 比 Bash Shell 小的多,符合POSIX標准。
Ubuntu繼承了Debian,所以從Ubuntu 6.10開始默認是Dash Shell。
-
luotaijia@ubuntu:~$ ls -l /bin/sh /bin/bash
-
-rwxr-xr-x 1 root root 801808 2010-08-11 03:58 /bin/bash
-
lrwxrwxrwx 1 root root 4 2012-11-28 08:06 /bin/sh -> dash
應該說, /bin/sh 與 /bin/bash 雖然大體上沒什么區別, 但仍存在不同的標准. 標記為 “#!/bin/sh” 的腳本不應使用任何 POSIX 沒有規定的特性 (如 let 等命令, 但 “#!/bin/bash” 可以). Debian 曾經采用 /bin/bash 更改 /bin/dash,目的使用更少的磁盤空間、提供較少的功能、獲取更快的速度。但是后來經過 shell 腳本測試存在運行問題。因為原先在 bash shell 下可以運行的 shell script (shell 腳本),在 /bin/sh 下還是會出現一些意想不到的問題,不是100%的兼用。
-
1 a=12345
-
2
-
3 let "a += 1"
-
4 echo "a = $a"
-
5
-
6 b=${a/23/BB}
-
7 echo "b = $b"
-
luotaijia@ubuntu:~/文檔/shell學習練習$ /bin/sh 3.2..1.sh
-
3.2..1.sh: 3: let: not found
-
a = 12345
-
3.2..1.sh: 6: Bad substitution
-
luotaijia@ubuntu:~/文檔/shell學習練習$ /bin/bash 3.2..1.sh
-
a = 12346
-
b = 1BB46
-
luotaijia@ubuntu:~/文檔/shell學習練習$
-