/bin/bash 與 /bin/sh 的區別


 

[aimin@localhost ~]$ ll /bin/sh
lrwxrwxrwx. 1 root root 4 Oct 14  2017 /bin/sh -> bash
[aimin@localhost ~]$ ll /bin/bash
-rwxr-xr-x. 1 root root 938768 Feb 21  2013 /bin/bash
[aimin@localhost ~]$ bash
[aimin@localhost ~]$ which bash
/bin/bash
[aimin@localhost ~]$

--------------------------------------

1. sh一般設成bash的軟鏈
[work@zjm-testing-app46 cy]$ ll /bin/sh
lrwxrwxrwx 1 root root 4 Nov 13 2006 /bin/sh -> bash
2. 在一般的linux系統當中(如redhat),使用sh調用執行腳本相當於打開了bash的POSIX標准模式
3. 也就是說 /bin/sh 相當於 /bin/bash --posix

所以,sh跟bash的區別,實際上就是bash有沒有開啟posix模式的區別

(遵循posix的特定規范,有可能就包括這樣的規范:“當某行代碼出錯時,不繼續往下解釋”)

--------------------------------------

 它們之間的各種差異都是來自 POSIX 標准模式 和 bash 的差異,比如 用 : 截取字符串,不能用 let , 遇錯中斷 等等,在使用時需要注意。

--------------------------------------

(1)sh test.sh :即使在腳本中指定了#!/bin/bash,但仍然是使用/bin/sh執行test.sh
(2)chmod u+x test.sh;./test.sh :這種執行方式會按照腳本第一行指定的shell執行

--------------------------------------

 

REF

https://stackoverflow.com/questions/5725296/difference-between-sh-and-bash

https://askubuntu.com/questions/766270/what-is-posix-compatible-mode-in-linux

https://askubuntu.com/questions/422492/why-script-with-bin-bash-is-working-with-bin-sh-not

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM