Merge pull request #15324 from wxy/20190903-The-birth-of-the-Bash-shell

TSL&PRF:20190903 The birth of the Bash shell
This commit is contained in:
Xingyu.Wang 2019-09-07 14:35:39 +08:00 committed by GitHub
commit d71122c3d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 102 additions and 104 deletions

View File

@ -1,104 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (wxy)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (The birth of the Bash shell)
[#]: via: (https://opensource.com/19/9/command-line-heroes-bash)
[#]: author: (Matthew Broberg https://opensource.com/users/mbbroberghttps://opensource.com/users/mbbroberghttps://opensource.com/users/mbbroberghttps://opensource.com/users/mbbroberg)
The birth of the Bash shell
======
This week's Command Line Heroes podcast delves into the most widely used
and de facto standard scripting language, its early inspirations as part
of the Free Software Foundation, and its author.
![Listen to the Command Line Heroes Podcast][1]
Shell scripting is an essential discipline for anyone in a sysadmin type of role, and the predominant shell in which people write scripts today is Bash. Bash comes as default on nearly all Linux distributions and modern MacOS versions and is slated to be a native part of [Windows Terminal][2] soon enough. Bash, you could say, is everywhere.
So how did it get to this point? This week's [Command Line Heroes][3] podcast dives deeply into that question by asking the very people who wrote the code.
### It started with Unix
Like all programming things, we have to go back to Unix. A little shell history: In 1971, Ken Thompson released the first Unix shell—the Thompson shell. But there were severe limitations to the amount of scripting users could do. And that meant serious limitations for automation and, consequently, for the whole field of IT operations.
This [fantastic piece of research][4] outlines the challenges to early attempts at scripting (bold added to highlight commands):
> Similar to its predecessor in Multics, this shell (**/bin/sh**) was an independent user program that executed outside of the kernel. Concepts like globbing (pattern matching for parameter expansion, such as ***.txt**) were implemented in a separate utility called **glob**, as was the **if** command to evaluate conditional expressions. This separation kept the shell small, at under 900 lines of C source.
>
> The shell introduced a compact syntax for redirection (**< >** and **>>**) and piping (**|** or **^**) that has survived into modern shells. You can also find support for invoking sequential commands (with **;**) and asynchronous commands (with **&**).
>
> What the Thompson shell lacked was the ability to script. Its sole purpose was as an interactive shell (command interpreter) to invoke commands and view results.
As the access to terminals grew, an interest in automation grew along with it.
### Bourne shell is a step forward
Six years after Thompson's release, in 1977, Stephen Bourne released the Bourne shell, which was meant to solve the scripting limitations of the Thompson shell. (Chet Ramey, the primary maintainer of the Bash language since 1990, discusses it on this episode of Command-Line Heroes). It was the natural evolution of technology coming out of Bell Labs as part of the Unix system.
What did Bourne intend to do differently? [Researcher M. Jones][4] outlines it well: 
> The Bourne shell had two primary goals: serve as a command interpreter to interactively execute commands for the operating system and for scripting (writing reusable scripts that could be invoked through the shell). In addition to replacing the Thompson shell, the Bourne shell offered several advantages over its predecessors. Bourne introduced control flows, loops, and variables into scripts, providing a more functional language to interact with the operating system (both interactively and noninteractively). The shell also permitted you to use shell scripts as filters, providing integrated support for handling signals, but lacked the ability to define functions. Finally, it incorporated a number of features we use today, including command substitution (using back quotes) and HERE documents to embed preserved string literals within a script.
Bourne, in a [previous interview][5], described it this way:
> The original shell wasnt really a language; it was a recording—a way of executing a linear sequence of commands from a file, the only control flow primitive being GOTO a label. These limitations to the original shell that Ken Thompson wrote were significant. You couldnt, for example, easily use a command script as a filter because the command file itself was the standard input. And in a filter, the standard input is what you inherit from your parent process, not the command file.
>
> The original shell was simple but, as people started to use Unix for application development and scripting, it was too limited. It didnt have variables, it didnt have control flow, and it had very inadequate quoting capabilities.
This new shell was a huge step forward for scripters, but only if you had access to it.
### Rethinking Bourne's shell as free software
Until then, the dominant shells were proprietary software that was owned and operated at Bell Labs. If you were fortunate enough, your university might have access to a Unix shell. But that restricted access was far from the world that the Free Software Foundation (FSF) wanted to achieve. 
Richard Stallman and a group of like-minded developers were writing all the features of Unix with a license that is freely available under the GNU license. One of those developers was tasked with making a shell. That developer was Brian Fox. And the way he talks about his task absolutely fascinates me. As he says on the podcast:
> The reason it was so challenging was that we had to faithfully mimic all of the behaviors of the Bourne shell, while at the same time being allowed to extend it to make it a better tool for people to use.
This was also at a time when people were discussing what it meant to be a shell standard. With this history as background and competition in the foreground, the popular Bourne shell was reimagined; born again.
### The shell, Bourne-Again
These two catalysts—the free software mission and competition—brought the Bourne-Again shell (Bash) to life. In an unusual move for the time, Fox didn't name his shell after himself, and he focused on the evolution from Unix to free software. (Although Fox Shell could have beaten Fish shell to the fsh command #missedopportunity). That naming choice seems aligned with his personality. As Fox says in the episode, he wasn't interested in even the perception of personal glory; he was trying to help the culture of programming evolve. He was not, however, above a good pun.
It was nice to hear that Bourne didn't feel slighted by the play on words. Bourne tells a story about when someone walked up to him and gave him a Bash t-shirt at a conference. That person was Brian Fox.
Shell | Released | Creator
---|---|---
Thompson Shell | 1971 | Ken Thompson
Bourne Shell | 1977 | Stephen Bourne
Bourne-Again Shell | 1989 | Brian Fox
With time, Bash grew in adoption. Other engineers started using it and submitting improvements to its design. Indeed, years later, Fox would insist that learning to give up control of Bash was one of the most important things he did in his life. As Unix gave way to Linux and the open source software movement, Bash became the key scripting force in an open source world. Great projects seem to grow beyond the scope of a single person's vision.
### What can we learn from shells?
A shell is a technology that is so integral to everyday laptop use that it's easy to forget it needed invention. The story of going from Thompson to Bourne to Bash shells draws some familiar takeaways:
* Motivated individuals can make great strides with the right mission in mind.
* Much of what we rely on today is built on the work of still-living legends in our industry.
* The software that tends to survive are the ones that evolve beyond the vision of their original creators.
Command Line Heroes has covered programming languages for all of Season 3 and is approaching its finale. [Be sure to subscribe to learn everything you want to know about the origin of programming languages][3], and I would love to hear your shell stories in the comments below.
--------------------------------------------------------------------------------
via: https://opensource.com/19/9/command-line-heroes-bash
作者:[Matthew Broberg][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/mbbroberghttps://opensource.com/users/mbbroberghttps://opensource.com/users/mbbroberghttps://opensource.com/users/mbbroberg
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/commnad_line_hereoes_ep6_blog-header-292x521.png?itok=Bs1RlwoW (Listen to the Command Line Heroes Podcast)
[2]: https://devblogs.microsoft.com/commandline/introducing-windows-terminal/
[3]: https://www.redhat.com/en/command-line-heroes
[4]: https://developer.ibm.com/tutorials/l-linux-shells/
[5]: https://www.computerworld.com.au/article/279011/-z_programming_languages_bourne_shell_sh

View File

@ -0,0 +1,102 @@
[#]: collector: (lujun9972)
[#]: translator: (wxy)
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-11314-1.html)
[#]: subject: (The birth of the Bash shell)
[#]: via: (https://opensource.com/19/9/command-line-heroes-bash)
[#]: author: (Matthew Broberg https://opensource.com/users/mbbroberghttps://opensource.com/users/mbbroberghttps://opensource.com/users/mbbroberghttps://opensource.com/users/mbbroberg)
Bash shell 的诞生
======
> 本周的《代码英雄》播客深入研究了最广泛使用的、已经成为事实标准的脚本语言,它来自于自由软件基金会及其作者的早期灵感。
![Listen to the Command Line Heroes Podcast][1]
对于任何从事于系统管理员方面的人来说Shell 脚本编程是一门必不可少的技能,而如今人们编写脚本的主要 shell 是 Bash。Bash 是几乎所有的 Linux 发行版和现代 MacOS 版本的默认配置,也很快就会成为 [Windows 终端][2]的原生部分。你可以说 Bash 无处不在。
那么它是如何做到这一点的呢?本周的《[代码英雄][3]》播客将通过询问编写那些代码的人来深入研究这个问题。
### 肇始于 Unix
像所有编程方面的东西一样,我们必须追溯到 Unix。shell 的简短历史是这样的1971 年Ken Thompson 发布了第一个 Unix shellThompson shell。但是脚本用户所能做的存在严重限制这意味着严重制约了自动化以及整个 IT 运营领域。
这个[奇妙的研究][4]概述了早期尝试脚本的挑战:
> 类似于它在 Multics 中的前身,这个 shell`/bin/sh`)是一个在内核外执行的独立用户程序。诸如通配(参数扩展的模式匹配,例如 `*.txt`)之类的概念是在一个名为 `glob` 的单独的实用程序中实现的,就像用于计算条件表达式的 `if` 命令一样。这种分离使 shell 变得更小,才不到 900 行的 C 源代码。
>
> shell 引入了紧凑的重定向(`<`、`>` 和 `>>`)和管道(`|` 或 `^`)语法,它们已经存在于现代 shell 中。你还可以找到对调用顺序命令(`;`)和异步命令(``)的支持。
>
> Thompson shell 缺少的是编写脚本的能力。它的唯一目的是作为一个交互式 shell命令解释器来调用命令和查看结果。
随着对终端使用的增长,对自动化的兴趣随之增长。
### Bourne shell 前进一步
在 Thompson 发布 shell 六年后1977 年Stephen Bourne 发布了 Bourne shell旨在解决Thompson shell 中的脚本限制。Chet Ramey 是自 1990 年以来 Bash 语言的主要维护者,在这一集的《代码英雄》中讨论了它)。作为 Unix 系统的一部分,这是这个来自贝尔实验室的技术的自然演变。
Bourne 打算做什么不同的事情?[研究员 M. Jones][4] 很好地概述了它:
> Bourne shell 有两个主要目标:作为命令解释器以交互方式执行操作系统的命令,和用于脚本编程(编写可通过 shell 调用的可重用脚本)。除了替换 Thompson shellBourne shell 还提供了几个优于其前辈的优势。Bourne 将控制流、循环和变量引入脚本,提供了更具功能性的语言来(以交互式和非交互式)与操作系统交互。该 shell 还允许你使用 shell 脚本作为过滤器,为处理信号提供集成支持,但它缺乏定义函数的能力。最后,它结合了我们今天使用的许多功能,包括命令替换(使用后引号)和 HERE 文档(以在脚本中嵌入保留的字符串文字)。
Bourne 在[之前的一篇采访中][5]这样描述它:
> 最初的 shell (编程语言)不是一种真正的语言;它是一种记录 —— 一种从文件中线性执行命令序列的方法,唯一的控制流的原语是 `GOTO` 到一个标签。Ken Thompson 所编写的这个最初的 shell 的这些限制非常重要。例如,你无法简单地将命令脚本用作过滤器,因为命令文件本身是标准输入。而在过滤器中,标准输入是你从父进程继承的,不是命令文件。
>
> 最初的 shell 很简单,但随着人们开始使用 Unix 进行应用程序开发和脚本编写,它就太有限了。它没有变量、它没有控制流,而且它的引用能力非常不足。
对于脚本编写者来说,这个新 shell 是一个巨大的进步,但前提是你可以使用它。
### 以自由软件来重新构思 Bourne Shell
在此之前,这个占主导地位的 shell 是由贝尔实验室拥有和管理的专有软件。幸运的话,你的大学可能有权访问 Unix shell。但这种限制性访问远非自由软件基金会FSF想要实现的世界。
Richard Stallman 和一群志同道合的开发人员那时正在编写所有的 Unix 功能,其带有可以在 GNU 许可证下免费获得的许可。其中一个开发人员的任务是制作一个 shell那位开发人员是 Brian Fox。他对他的任务的讲述十分吸引我。正如他在播客上所说
> 它之所以如此具有挑战性,是因为我们必须忠实地模仿 Bourne shell 的所有行为,同时允许扩展它以使其成为一个供人们使用的更好工具。
而那时也恰逢人们在讨论 shell 标准是什么的时候。在这一历史背景和将来的竞争前景下,流行的 Bourne shell 被重新构想,并再次重生。
### 重新打造 Bourne Shell
自由软件的使命和竞争这两个催化剂使重制的 Bourne shellBash具有了生命。和之前不同的是Fox 并没有把 shell 放到自己的名字之后命名,他专注于从 Unix 到自由软件的演变。(虽然 Fox Shell 这个名字看起来要比 Fish shell 更适合作为 fsh 命令 #missedopportunity)。这个命名选择似乎符合他的个性。正如 Fox 在剧集中所说,他甚至对个人的荣耀也不感兴趣;他只是试图帮助编程文化发展。然而,他并不是一个优秀的双关语。
而 Bourne 也并没有因为他命名 shell 的文字游戏而感到被轻视。Bourne 讲述了一个故事,有人走到他面前,并在会议上给了他一件 Bash T 恤,而那个人是 Brian Fox。
Shell | 发布于 | 创造者
---|---|---
Thompson Shell | 1971 | Ken Thompson
Bourne Shell | 1977 | Stephen Bourne
Bourne-Again Shell | 1989 | Brian Fox
随着时间的推移Bash 逐渐成长。其他工程师开始使用它并对其设计进行改进。事实上多年后Fox 坚定地认为学会放弃控制 Bash 是他一生中最重要的事情之一。随着 Unix 让位于 Linux 和开源软件运动Bash 成为开源世界的至关重要的脚本语言。这个伟大的项目似乎超出了单一一个人的愿景范围。
### 我们能从 shell 中学到什么?
shell 是一项技术,它是笔记本电脑日常使用中的一个组成部分,你很容易忘记它也需要发明出来。从 Thompson 到 Bourne 再到 Bashshell 的故事为我们描绘了一些熟悉的结论:
* 有动力的人可以在正确的使命中取得重大进展。
* 我们今天所依赖的大部分内容都建立在我们行业中仍然活着的那些传奇人物打下的基础之上。
* 能够生存下来的软件超越了其原始创作者的愿景。
  
代码英雄在全部的第三季中讲述了编程语言,并且正在接近它的尾声。[请务必订阅,来了解你想知道的有关编程语言起源的各种内容][3],我很乐意在下面的评论中听到你的 shell 故事。
--------------------------------------------------------------------------------
via: https://opensource.com/19/9/command-line-heroes-bash
作者:[Matthew Broberg][a]
选题:[lujun9972][b]
译者:[wxy](https://github.com/wxy)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/mbbroberghttps://opensource.com/users/mbbroberghttps://opensource.com/users/mbbroberghttps://opensource.com/users/mbbroberg
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/commnad_line_hereoes_ep6_blog-header-292x521.png?itok=Bs1RlwoW (Listen to the Command Line Heroes Podcast)
[2]: https://devblogs.microsoft.com/commandline/introducing-windows-terminal/
[3]: https://www.redhat.com/en/command-line-heroes
[4]: https://developer.ibm.com/tutorials/l-linux-shells/
[5]: https://www.computerworld.com.au/article/279011/-z_programming_languages_bourne_shell_sh