为什么脚本适用于/ bin/bash而不是/ bin/sh?

0 bash shell sh

我试图理解为什么脚本可以使用#!/bin/bash但不是#!/bin/sh.我运行Cygwin和都sh.exebash.exe似乎是相同的(相同的文件大小).

$ cat 1.sh
#!/bin/sh
while read line; do
  echo ${line:0:9}
done < <(help | head -5)

$ ./1.sh
./1.sh: line 4: syntax error near unexpected token `<'
./1.sh: line 4: `done < <(help | head -5)'

$ cat 2.sh
#!/bin/bash
while read line; do
  echo ${line:0:9}
done < <(help | head -5)

$ ./2.sh
GNU bash,
These she
Type `hel
Use `info
Use `man
Run Code Online (Sandbox Code Playgroud)

Ole*_*kov 5

尽管是相同的文件,但shell在运行时会分析自己的名称,并切换到普通shell或bash模式.