bash和zsh区别_Bash,Zsh和其他Linux Shell之间有什么区别?

bash和zsh区别

bash和zsh区别

Most Linux distributions include the bash shell by default, but you could also switch to another shell environment. Zsh is a particularly popular alternative, and there are other shells, like ash, dash, fish, and tcsh. But what’s the difference, and why are there so many?

大多数Linux发行版默认都包含bash shell,但是您也可以切换到另一个shell环境。 Zsh是一个特别受欢迎的替代方案,并且还有其他外壳,例如灰烬,破折号,鱼和tcsh。 但是有什么区别,为什么会有那么多呢?

贝壳做什么? (What Do Shells Do?)

When you sign in at the command line or launch a terminal window on Linux, the system launches the shell program. Shells offer a standard way of extending the command line environment. You can swap out the default shell for another one, if you like.

在Linux上通过命令行登录或启动终端窗口时,系统将启动Shell程序。 Shell提供了扩展命令行环境的标准方法。 如果愿意,可以将默认外壳换成另一个外壳。

The first shell environment was the Thompson Shell, developed at Bell Labs and released in 1971. Shell environments have been building on the concept ever since, adding a variety of new features, functionality, and speed improvements.

第一个外壳程序环境是由Bell Labs开发并于1971年发布的Thompson Shell。此后,外壳程序环境一直以此概念为基础,并增加了许多新功能,功能和速度方面的改进。

For example, Bash offers command and file name completion, advanced scripting features, a command history, configurable colors, command aliases, and a variety of other features that weren’t available back in 1971 when the first shell was released.

例如,Bash提供命令和文件名补全高级脚本功能命令历史记录,可配置的颜色,命令别名以及其他各种功能,这些功能在1971年第一个Shell发行时就不可用。

The shell is also used in the background by various system services. Linux distributions include many functions written as shell scripts. These scripts are commands and other advanced shell scripting functions run through the shell environment.

各种系统服务还在后台使用该Shell。 Linux发行版包含许多作为shell脚本编写的功能。 这些脚本是在外壳环境中运行的命令和其他高级外壳脚本功能。

导致Bash的Shell:sh,csh,tsh和ksh (Shells Leading Up to Bash: sh, csh, tsh, and ksh)

The most prominent progenitor of modern shells is the Bourne shell—also known as “sh”—which was named after its creator Stephen Bourne who worked at AT&T’s Bell Labs. Released in 1979, it became the default command-interpreter in Unix because of its support for command substitution, piping, variables, condition testing, and looping, along with other features. It did not offer much customization for users, and didn’t support such modern niceties as aliases, command completion, and shell functions (though this last one was eventually added).

现代贝壳最著名的祖先是Bourne贝壳(也称为“ sh”),它是以在AT&T贝尔实验室工作的创造者Stephen Bourne的名字命名的。 它于1979年发布,由于它支持命令替换,管道,变量,条件测试和循环以及其他功能,因此成为Unix中的默认命令解释器。 它没有为用户提供太多自定义功能,并且不支持诸如别名,命令完成和shell函数之类的现代功能(尽管最后添加了最后一个功能)。

The C shell, or “csh”, was developed in the late 1970s by Bill Joy at University of California, Berkley. It added a lot of interactive elements with which users could control their systems, like aliases (shortcuts for long commands), job management abilities, command history, and more. It was modeled off the C programming language, which the Unix operating system itself was written in. This also meant that users of the Bourne shell had to learn C so they could enter commands in it. In addition, csh had quite a few bugs that had to be hammered out by users and creators alike over a large period of time. People ended up using the Bourne shell for scripts because it handled non-interactive commands better, but stuck with the C shell for normal use.

C shell或“ csh”是1970年代后期由加州大学伯克利分校的Bill Joy开发的。 它添加了许多交互式元素,用户可以使用它们来控制系统,例如别名(长命令的快捷方式),作业管理能力,命令历史记录等等。 它是使用C语言编程的,该语言是Unix操作系统本身编写的。这也意味着Bourne shell的用户必须学习C语言,以便可以在其中输入命令。 另外,csh还有很多错误,在很长一段时间内,用户和创作者都必须解决这些错误。 人们最终将Bourne shell用于脚本,因为它可以更好地处理非交互式命令,但在正常使用时会停留在C shell中。

Over time, lots of people fixed bugs in and added features to the C shell, culminating in an improved version of csh known as “tcsh”. But csh was still the default in Unix-based computers, and had added some non-standard features. David Korn from Bell Labs worked on the KornShell, or “ksh”, which tried to improve the situation by being backwards-compatible with the Bourne shell’s language but adding many features from the csh shell. It was released in 1983, but under a proprietary license. It wasn’t free software until the 2000s, when it was released under various open-source licenses.

随着时间的流逝,许多人修复了C shell中的错误并为其添加了功能,最终导致了改进的csh版本,即“ tcsh”。 但是csh仍然是基于Unix的计算机中的默认设置,并添加了一些非标准功能。 贝尔实验室的David Korn开发了KornShell或“ ksh”,该产品试图通过与Bourne Shell的语言向后兼容,但从csh shell添加了许多功能来改善这种情况。 它于1983年发布,但获得了专有许可。 直到2000年代,它才是免费软件,当时它是在各种开源许可证下发布的。

bash的诞生 (The Birth of bash)

The Portable Operating System Interface for Unix, or POSIX, was another response to the hectic proprietary csh implementations. It successfully created a standard for command interpretation (among other things) and eventually mirrored a lot of the features in the KornShell. At the same time, the GNU Project was attempting to create a free, Unix-compatible operating system. The GNU Project developed a free software shell to be part of its free operating system and named it the “Bourne Again Shell”, or “bash”.

Unix的便携式操作系统接口,即POSIX,是对忙碌的专有csh实现的另一种回应。 它成功创建了命令解释标准(除其他外),并最终反映了KornShell中的许多功能。 同时,GNU工程正试图创建一个免费的,兼容Unix的操作系统。 GNU项目开发了一个免费软件外壳程序作为其免费操作系统的一部分,并将其命名为“ Bourne Again Shell”或“ bash”。

Bash has been improved in the decades since its first release in 1989, but it’s still the default shell on most Linux distributions today. It’s also the default shell on Apple’s macOS, and is available for installation on Microsoft’s Windows 10.

自1989年首次发布以来,Bash在几十年中得到了改进,但是它仍然是当今大多数Linux发行版中的默认Shell。 它也是Apple macOS上的默认外壳,可用于在Microsoft Windows 10上安装

较新的外壳:灰,破折号,zsh和鱼 (Newer Shells: ash, dash, zsh, and fish)

While the Linux community has settled on Bash in the years since, developers didn’t stop creating new shells when Bash was first released 28 years ago.

从那以后,Linux社区就开始使用Bash了,但是当Bash在28年前首次发布时,开发人员并没有停止创建新的Shell。

Kenneth Almquist created a Bourne shell clone known as Almquish shell, A Shell, “ash”, or sometimes just “sh”. it was also POSIX compatible and became the default shell in BSD, a different branch of Unix. The ash shell is more lightweight than bash, which makes it popular in embedded Linux systems. If you have a rooted Android phone with BusyBox installed—or any other device with the BusyBox suite of software—it’s using code from ash.

肯尼斯·阿尔姆奎斯特(Kenneth Almquist)创建了一个伯恩(Bourne)壳克隆,称为阿尔姆奎什壳(Almquish shell),“壳”,“灰”或有时仅称为“ sh”。 它也与POSIX兼容,并成为BSD (Unix的另一个分支)中的默认Shell。 ash外壳比bash轻巧,这使其在嵌入式Linux系统中很受欢迎。 如果您有安装了BusyBox的扎根Android手机-或安装了BusyBox软件套件的任何其他设备-则使用的是ash中的代码。

Debian developed a shell environment based on ash and called it “dash”. It’s designed to be POSIX-compliant and lightweight, so it’s faster than Bash, but won’t have all its features. Ubuntu uses the dash shell as its default shell for non-interactive tasks, speeding up shell scripts and other tasks running in the background. Ubuntu still uses bash for interactive shells, however, so users still have the full-featured interactive environment.

Debian开发了基于ash的shell环境,并将其称为“破折号”。 它被设计为符合POSIX且轻巧,因此比Bash更快,但不会具有所有功能。 Ubuntu使用破折号外壳作为非交互式任务的默认外壳,从而加快了外壳脚本和其他在后台运行的任务的速度。 Ubuntu仍将bash用于交互式shell,因此用户仍具有功能齐全的交互式环境。

One of the most popular newer shells is Z shell, or “zsh”. Created by Paul Falstad in 1990, zsh is a Bourne-style shell that contains the features you’ll find in bash, plus even more. For example, zsh has spell-checking, the ability to watch for logins/logouts, some built-in programming features like bytecode, support for scientific notation in syntax, allows for floating-point arithmetic, and more features.

最受欢迎的较新外壳之一是Z外壳,即“ zsh”。 zsh由Paul Falstad在1990年创建,是一种Bourne风格的shell,它包含bash中的功能以及更多功能。 例如,zsh具有拼写检查,监视登录/注销的能力,一些内置的编程功能(例如字节码),对语法的科学表示法的支持,允许进行浮点算术等功能。

Another newer shell is the Friendly Interactive Shell, or “fish”, released in 2005. It has a unique command-line syntax that’s designed to be a bit easier to learn, but isn’t derived from either the Bourne shell or C shell. It’s an interesting idea, but what you learn through using fish won’t necessarily help you use bash and other Bourne-derived shells.

另一个较新的外壳是2005年发布的Friendly Interactive Shell(即“鱼”)。它具有独特的命令行语法,旨在使其更易于学习,但它并非源于Bourne Shell或C Shell。 这是一个有趣的想法,但是您通过使用鱼学到的知识不一定能帮助您使用bash和其他Bourne衍生的贝壳。

您应该选择哪一个? (以及为什么Zsh受欢迎) (Which Should You Choose? (and Why Zsh is Popular))

You don’t need to choose a shell. Your operating system chooses your default shell for you, and that choice is almost always bash. Sit down in front a Linux distribution—or even a Mac—and you’ll almost always have a bash shell environment. Bash has quite a few advanced features, but you probably won’t use them unless you program shell scripts.

您无需选择外壳。 您的操作系统将为您选择默认外壳程序,而该选择几乎总是bash。 坐在Linux发行版甚至Mac的前面,您几乎总是拥有bash shell环境。 Bash具有许多高级功能,但是除非您编写Shell脚本,否则您可能不会使用它们。

On embedded Linux systems or BSD systems, you’ll end up with the ash shell. But ash is a Bourne-based shell and is largely compatible with bash. Any knowledge you have from using bash will transfer to using an ash or dash shell, although some advanced scripting features are not available in this lightweight shell.

在嵌入式Linux系统或BSD系统上,您将获得ash shell。 但是ash是基于Bourne的shell,并且与bash基本上兼容。 您从使用bash所获得的所有知识都将转换为使用ash或dash外壳,尽管此轻量级外壳中不提供某些高级脚本功能。

Almost every shell you’ll encounter is Bourne-based and works similarly—including zsh.

几乎您将遇到的每个shell都是基于Bourne的,并且工作方式相似-包括zsh。

That’s why zsh is popular. This newer shell is compatible with bash, but includes more features. The zsh shell offers built-in spelling correction, improved command-line completion, loadable modules that act as plug-ins for your shell, global aliases that allow you to alias file names or anything else on the command line instead of just commands, and more theming support. It’s like bash, but with a lot of extras, additional features, and configurable options you might appreciate if you spend a lot of time at the command line.

这就是zsh受欢迎的原因。 此更新的外壳程序与bash兼容,但包含更多功能。 zsh shell提供了内置的拼写更正,改进的命令行完成功能,充当shell插件的可加载模块,允许您为文件名或命令行中的其他任何内容加上别名的全局别名,而不仅仅是命令,以及更多主题支持。 就像bash一样,但是如果您在命令行中花费大量时间,则可能会欣赏很多附加功能,附加功能和可配置选项。

If you’re familiar with bash, you can switch to zsh without learning a different syntax—you’ll just gain additional features. if you’re familiar with zsh, you can switch to bash without learning a different syntax—you just won’t have access to those features.

如果您熟悉bash,则可以切换到zsh,而无需学习其他语法-您将获得其他功能。 如果您熟悉zsh,则可以在不学习其他语法的情况下切换到bash-您将无法使用这些功能。

Oh My ZSH” is a tool that helps you more easily enable zsh plug-ins and switch between premade themes, quickly customizing your zsh shell without spending hours tweaking things.

Oh My ZSH ”工具可帮助您更轻松地启用zsh插件并在预制主题之间切换,从而快速自定义zsh shell,而无需花费大量时间进行调整。

There are other shells, too. For example, the tcsh shell is still around and is still an option. FreeBSD uses tsch as its default root shell and ash as its default interactive shell. If you use the C programming regularly, tsch might be a better fit for you. However, it’s nowhere near as commonly used as bash or zsh.

也有其他外壳。 例如,tcsh shell仍然存在并且仍然是一个选项。 FreeBSD使用tsch作为其默认的根shell,使用ash作为其默认的交互式shell。 如果您定期使用C编程,则tsch可能更适合您。 但是,它远不及bash或zsh常用。

如何在外壳之间切换 (How to Switch Between Shells)

It’s easy to switch to a new shell to try it out. Just install the shell from your Linux distribution’s package manager and type the command to launch the shell.

切换到新的外壳进行尝试很容易。 只需从Linux发行版的软件包管理器中安装Shell,然后键入命令以启动Shell。

For example, let’s say you want to try zsh on Ubuntu. You’d run the following commands to install and then launch it:

例如,假设您要在Ubuntu上尝试zsh。 您将运行以下命令来安装然后启动它:

sudo apt install zsh

zsh

You’d then be sitting at a zsh shell. Type ” exit ” at the shell to leave it and return to your current shell.

然后,您将坐在zsh shell中。 在外壳上键入“ exit ”离开它并返回到您当前的外壳。

This is just temporary. Whenever you open a new terminal window or sign into your system at the command line, you’ll see your default shell. To change the shell you see when you sign in—known as your login shell—you can generally use the chsh , or “Change Shell”, command.

这只是暂时的。 每当您打开新的终端窗口或在命令行登录系统时,您都会看到默认的外壳程序。 要更改登录时看到的外壳(称为登录外壳),通常可以使用chsh或“更改外壳”命令。

To use this command, you’ll first need to find the full path to your shell with the which command. For example, let’s say we wanted to change to the zsh shell. We’d run the following command:

要使用此命令,您首先需要使用which命令找到您的shell的完整路径。 例如,假设我们要更改为zsh shell。 我们将运行以下命令:

which zsh

On Ubuntu, this tells us the zsh binary is stored at /usr/bin/zsh.

在Ubuntu上,这告诉我们zsh二进制文件存储在/ usr / bin / zsh中。

Run the following command, enter your password, and you’ll be prompted to choose a new login shell:

运行以下命令,输入密码,系统将提示您选择一个新的登录shell:

chsh

According to the above command, we’d enter /usr/bin/zsh . The zsh shell would then be our default until we ran the chsh command and changed it back.

根据以上命令,我们将输入/usr/bin/zsh 。 在我们运行chsh命令并将其改回之前,zsh shell将成为我们的默认设置。

翻译自: https://www.howtogeek.com/68563/htg-explains-what-are-the-differences-between-linux-shells/

bash和zsh区别

  • 5
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值