b/w Bash 和 Shell 脚本有什么区别

What is the difference b/w Bash and Shell script

我为 UNIX 和 Windows 编写脚本已经将近 3 年了。我一直对这两个术语感到困惑,有一段时间我认为 bash 脚本是 windows cmd 脚本而 shell 脚本是 UNIX 脚本,但我了解到这是不正确。那么这两个术语有什么区别:BASH 和 Shell 脚本?

同理Windows,LinuxMacOSX操作系统,或奥迪福特雪佛兰汽车: windows' cmd.exe, BASH, ZSH, CSH, TCSH, Korn Shell, Bourne Shell...只是不同种类的shells.

一般来说,"shell" 是设计用户界面的类比,可以访问系统的"core"。所以在这种情况下,shell 是用于操作系统的文本界面(也称为 命令行界面 又名 CLI)。

现在,当您谈论 "shell scripting" 时,它只是使用为用户界面开发的语言来自动执行该系统上的任务。存在一些面向图形的脚本(如 Office 的宏),但大多数时候它是关于创建一个 "batch" 文件(Dos/Windows 上的 .bat)或者在 unix 世界中被称为 "shell script".

这里有一些维基百科文章可以阅读更多相关信息:

"Shell script" 是由 shell.

执行的脚本的通用术语

"Bash script" 是一个更具体的术语;它指的是由一个特定的 shell、Bash shell.

执行的脚本

A shell 是命令解释程序。它可以交互使用(用户在提示符下键入命令,然后 shell 执行它们),或用作脚本的解释器(将一系列命令写入文件)。

Bourne shell 是 UNIX 上较旧的 shell 之一(不是最古老的,但我们不必担心古老的历史)。其他几个 shell 已作为 Bourne shell.

的替代或扩展实现。

特别是,GNU Bash 可能是最近最常用的 shell。它实现了与 Bourne shell 相同的功能,外加一些扩展。

Bourne shell 脚本通常以 "Shebang" 行开头:

#!/bin/sh

Bash 脚本通常以指定 Bash shell:

的 Shebang 开头
#!/bin/bash

并且可能取决于 Bash 而不是 Bourne shell 实现的功能。

(在某些操作系统上,/bin/sh 可能与 /bin/bash 是同一个命令。)

并非所有 Unix shell 都基于 Bourne shell。特别是,csh 及其派生词 tcsh 在很大程度上与 Bourne 派生的 shell 不兼容。

Bash 与 Windows cmd 脚本没有什么关系,只是 Bash 和 cmd.exe 都是命令解释器。

根据维基百科:

A shell script is a computer program designed to be run by the Unix shell, a command line interpreter.[1] The various dialects of shell scripts are considered to be scripting languages.

来源:https://en.wikipedia.org/wiki/Shell_script

Bash is a command processor that typically runs in a text window, where the user types commands that cause actions. Bash can also read commands from a file, called a script.

换句话说,bash只是一个shell(流行的),shell脚本是一个可以被shell解释的脚本。为了满足您的好奇心,这里列出了 shell:https://en.wikipedia.org/wiki/Unix_shell#Shell_categories

Shell scripts 是系统 shell.

可以 运行 的任何脚本的通用名称

现在 shell 一个接受命令并执行它们的程序 - 一种 REPL / 命令解释器。 sh 是一个 shell。 bashfishzsh等也是

cmd有时被称为Windowsshell,但windows shell是WindowsUI的正式名称。 Microsoft 称之为 command interpreter(更多名称混淆)。

cmdmsdos 的脚本通常称为 "batch scripts"。

所以在 *nix 领域通常是:"bash" 执行 "shell scripts"。在 windows 区域:"cmd"(dos 提示符)执行 "batch scripts".