/bin/sh 与 /bin/bash 的区别

 /bin/sh/bin/bash 的区别,用 : 截取字符串不是POSIX 标准的。

区别

  1. sh 一般设成 bash 的软链 (symlink)
    1. ls -l /bin/sh  
    2. lrwxrwxrwx 1 root root 4 Sep 14 04:45 /bin/sh -> dash  
  2. 在一般的 linux 系统当中(例外如 FreeBSD,OpenBSD 等),使用 sh 调用执行脚本相当于打开了bashPOSIX 标准模式
  3. 也就是说 /bin/sh 相当于 /bin/bash --posix

所以,它们之间的各种差异都是来自 POSIX 标准模式bash 的差异,比如 用 : 截取字符串,不能用 let , 遇错中断 等等,在使用时需要注意。

参考

    1. [Difference between sh and bash] http://stackoverflow.com/questions/5725296/difference-between-sh-and-bash
    2. [/bin/bash和/bin/sh的区别] http://www.cppblog.com/erran/archive/2012/05/24/176038.aspx
    3. [#!/bin/sh與#!/bin/bash的區別] http://fanli7.net/a/bianchengyuyan/_NET/20130916/424894.html
原文地址:https://www.cnblogs.com/losbyday/p/5856300.html