Why will script work with /bin/bash but not /bin/sh?

前端 未结 2 2044
隐瞒了意图╮
隐瞒了意图╮ 2021-01-17 03:13

I am trying to understand why the script will work with #!/bin/bash but not #!/bin/sh. I am running Cygwin and both sh.exe and b

相关标签:
2条回答
  • 2021-01-17 03:46

    The Problems

    1. Bash is a superset of the Bourne shell, so many things are possible in Bash that aren't possible in more limited shells.
    2. Even when sh is a hardlink to bash, it behaves differently when invokes as sh. Many features supported by the Bash shell will not work in this mode.

    The Solutions

    1. Remove your bashisms from the script, including nifty features like the process substitution you have on line 4.
    2. Run your script as Bash, not vanilla Bourne.
    0 讨论(0)
  • 2021-01-17 03:47

    Despite being same file, shell analyzes its own name when run and switches to either plain shell or bash mode.

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