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

前端 未结 2 2046
隐瞒了意图╮
隐瞒了意图╮ 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条回答
  •  梦毁少年i
    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.

提交回复
热议问题