#!/bin/sh與#!/bin/bash的區別
阿新 • • 發佈:2018-01-24
shell學習 clas 基礎 not text 類型 css roo 快的
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。
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 中的優點,有靈活和強大的編程接口,同時又有很友好的用戶界面。
- 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
點擊(此處)折疊或打開
- 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學習練習$
#!/bin/sh與#!/bin/bash的區別