Why does bash behave differently, when it is called as sh?

后端 未结 3 1951
名媛妹妹
名媛妹妹 2021-01-16 17:55

I have an ubuntu machine with default shell set to bash and both ways to the binary in $PATH:

$ which bash
/bin/bash
$ which sh
/bin/sh
$ ll /bin/sh
lrwxrwxr         


        
相关标签:
3条回答
  • 2021-01-16 18:40

    When bash is invoked as sh, it (mostly) restricts itself to features found in the POSIX standard. Process substitution is not one of those features, hence the error.

    0 讨论(0)
  • 2021-01-16 18:41

    I believe sh on ubuntu is actually dash which is smaller than bash with fewer features.

    0 讨论(0)
  • 2021-01-16 18:56

    Theoretically, it is a feature of bash: if you call as "sh", it by default switches off all of its features. And the root shell is by default "/bin/sh".

    Its primary goal is the security. Secondary is the produce some level of compatibility between some shells of the system, because it enables the system scripts to run in alternate (faster? more secure?) environment.

    This is the theory.

    Practically goes this so, that there are always people in a development team, who want to reduce and eliminate everything with various arguments (security, simplicity, safety, stability - but these arguments are going somehow always to the direction of the removal, deletion, destroying).

    This is because the bash in debian doesn't have network sockets, this is because debian wasn't able in 20 years to normally integrate the best compressors (bz2, xz) - and this is because the root shell is by default so primitive, as of the PDP11 of the eighties.

    0 讨论(0)
提交回复
热议问题