为什么会用/斌/ bash脚本工作,但不是/ bin / sh的? [英] Why will script work with /bin/bash but not /bin/sh?

查看:127
本文介绍了为什么会用/斌/ bash脚本工作,但不是/ bin / sh的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图理解为什么脚本将#!/斌/庆典而不是#!/ bin / sh的。我运行Cygwin和两个 sh.exe bash.exe 似乎是相同的(相同的文件大小)。

$猫1.sh
#!/ bin / sh的
而读线;做
  回声$ {行:0:9}
完成< ≤(帮助|头-5)$ ./1.sh
./1.sh:4号线:附近意外的标记'&LT语法错误;'
./1.sh:4号线:做`< ≤(帮助|头-5)'$猫2.sh
#!/斌/庆典
而读线;做
  回声$ {行:0:9}
完成< ≤(帮助|头-5)$ ./2.sh
GNU的bash,
这些她
类型`HEL
使用`信息
使用`男人


解决方案

尽管是同一个文件,运行时分析的外壳以自己的名义切换为普通外壳或bash模式。

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 bash.exe seem to be identical (same file size).

$ 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

解决方案

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

这篇关于为什么会用/斌/ bash脚本工作,但不是/ bin / sh的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆