bash和dash的區別

來源:互聯網
上載者:User

http://zhidao.baidu.com/link?url=bwwK8H_9R06Kw8qpu5puh_s0Bb50YrOi9qsNvBe8ZKOteC_zfV8hJUPqIcQWJohLcH5jBgSlNJ5_5HQF-e1w-TlrpQnOa_zBcXdyVYZmoPm

Linux 作業系統預設的 shell 是Bourne Again shell,它是 Bourne shell 的擴充,簡稱 Bash,與 Bourne shell 完全向後相容,並且在Bourne shell 的基礎上增加、增強了很多特性。       GNU/Linux 作業系統中的 /bin/sh 本是 bash (Bourne-Again Shell) 的符號連結,但鑒於 bash 過於複雜,有人把 ash 從 NetBSD 移植到 Linux 並更名為 dash (Debian Almquist Shell),並建議將 /bin/sh 指向它,以獲得更快的指令碼執行速度。Dash Shell 比 Bash Shell 小的多,符合POSIX標準。Debian和Ubuntu中,/bin/sh預設已經指向dash,這是一個不同於bash的shell,它主要是為了執行指令碼而出現,而不是互動,它速度更快,但功能相比bash要少很多,文法嚴格遵守POSIX標準。文法上的主要的區別有:1.定義函數bash: function在bash中為關鍵字dash: dash中沒有function這個關鍵字2.select var in list; do command; donebash:支援dash:不支援, 替代方法:採用while+read+case來實現3. echo {0..10}bash:支援{n..m}展開dash:不支援,替代方法, 採用seq外部命令4. here stringbash:支援here stringdash:不支援, 替代方法:可採用here documents5. >&word重新導向標準輸出和標準錯誤bash: 當word為非數字時,>&word變成重新導向標準錯誤和標準輸出到檔案worddash: >&word, word不支援非數字, 替代方法: >word 2>&1; 常見用法 >/dev/null 2>&16. 數組bash: 支援數組, bash4支援關聯陣列dash: 不支援數組,替代方法, 採用變數名+序號來實作類別似的效果7. 子字串擴充bash: 支援${parameter:offset:length},${parameter:offset}dash: 不支援, 替代方法:採用expr或cut外部命令代替8. 大小寫轉換bash: 支援${parameter^pattern},${parameter^^pattern},${parameter,pattern},${parameter,,pattern}dash: 不支援,替代方法:採用tr/sed/awk等外部命令轉換9. 進程替換<(command), >(command)bash: 支援進程替換dash: 不支援, 替代方法, 通過臨時檔案中轉10. [ string1 = string2 ] 和 [ string1 == string2 ]bash: 支援兩者dash: 只支援=11. [[ 加強版testbash: 支援[[ ]], 可實現正則匹配等強大功能dash: 不支援[[ ]], 替代方法,採用外部命令12. for (( expr1 ; expr2 ; expr3 )) ; do list ; donebash: 支援C語言格式的for迴圈 dash: 不支援該格式的for, 替代方法,用while+$((expression))實現13. let命令和((expression))bash: 有內建命令let, 也支援((expression))方式dash: 不支援,替代方法,採用$((expression))或者外部命令做計算14. $((expression))bash: 支援id++,id--,++id,--id這樣到運算式dash: 不支援++,--, 替代方法:id+=1,id-=1, id=id+1,id=id-1

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.