【问题标题】:shell programming difference between #!/bm/bash and #!/bin/sh#!/bm/bash 和 #!/bin/sh 之间的 shell 编程区别
【发布时间】:2016-10-15 02:22:25
【问题描述】:

有人请告诉我#!/bm/bash 和#!/bin/sh 和链接之间有什么区别,以便更好地了解,以及为什么我们必须将它放在脚本的开头?

【问题讨论】:

  • 当您将脚本中的第一行设置为#!/bin/whatever 时,您将该文件的命令解释器 设置为/bin/whatever。因此,当您将其设置为 #!/bin/sh 时,您将文件的命令解释器设置为 /bin/sh 的任何内容(通常是 POSIX shell、dash 或 bourne shell)。当您将其设置为#!/bin/bash 时,您的意思是,“使用 bash 解释文件”。不多也不少。
  • /bin/sh 绝不是 POSIX 系统上的 Bourne shell,因为 Bourne shell 不符合 POSIX。

标签: linux bash shell bin


【解决方案1】:

bashsh 是两个不同的 shell。基本上bash 就是sh,具有更多的功能和更好的语法。

来自bash(1) man page

如果使用名称 sh 调用 bash,它会尽可能地模仿 sh 的历史版本的启动行为,同时也符合 POSIX 标准。

您必须放在第一行,表示脚本应该始终使用 bash 运行,而不是另一个 shell。

【讨论】:

    【解决方案2】:

    一个在sh shell 中运行脚本,另一个在bash shell 中运行。

    请参阅Difference between sh and bash

    【讨论】:

      猜你喜欢
      • 2011-09-03
      • 2022-06-28
      • 2012-02-20
      • 2013-01-19
      • 2011-08-09
      相关资源
      最近更新 更多