linux 默认shell_如何在 Linux 中安装、配置和使用 Fish Shell? | Linux 中国

f089ed146155e5ab3222997be7b363ca.png每个 Linux 管理员都可能听到过 shell 这个词。你知道什么是 shell 吗? 你知道 shell 在 Linux 中的作用是什么吗? Linux 中有多少个 shell 可用?-- Magesh Maruthamuthu

每个 Linux 管理员都可能听到过 shell 这个词。你知道什么是 shell 吗? 你知道 shell 在 Linux 中的作用是什么吗? Linux 中有多少个 shell 可用?

shell 是一个程序,它是提供用户和内核之间交互的接口。

内核是 Linux 操作系统的核心,它管理用户和操作系统之间的所有内容。Shell 可供所有用户在启动终端时使用。终端启动后,用户可以运行任何可用的命令。当 shell 完成命令的执行时,你将在终端窗口上获取输出。

Bash(全称是 Bourne Again Shell)是运行在今天的大多数 Linux 发行版上的默认的 shell,它非常受欢迎,并具有很多功能。但今天我们将讨论 Fish Shell 。

什么是 Fish Shell?

Fish[1] 是友好的交互式 shell ,是一个功能齐全,智能且对用户友好的 Linux 命令行 shell ,它带有一些在大多数 shell 中都不具备的方便功能。

这些功能包括自动补全建议、Sane Scripting、手册页补全、基于 Web 的配置器和 Glorious VGA Color 。你对它感到好奇并想测试它吗?如果是这样,请按照以下安装步骤继续安装。

如何在 Linux 中安装 Fish Shell ?

它的安装非常简单,除了少数几个发行版外,它在大多数发行版中都没有。但是,可以使用以下 fish 仓库[2] 轻松安装。

对于基于 Arch Linux 的系统, 使用 Pacman 命令[3] 来安装 fish shell。

$ sudo pacman -S fish

对于 Ubuntu 16.04/18.04 系统来说,请使用 APT-GET 命令[4] 或者 APT 命令[5] 安装 fish shell。

$ sudo apt-add-repository ppa:fish-shell/release-3$ sudo apt-get update$ sudo apt-get install fish

对于 Fedora 系统来说,请使用 DNF 命令[6] 安装 fish shell。

对于 Fedora 29 系统来说:

$ sudo dnf config-manager --add-repo https://download.opensuse.org/repositories/shells:/fish:/release:/3/Fedora_29/shells:fish:release:3.repo$ sudo dnf install fish

对于 Fedora 28 系统来说:

$ sudo dnf config-manager --add-repo https://download.opensuse.org/repositories/shells:/fish:/release:/3/Fedora_28/shells:fish:release:3.repo$ sudo dnf install fish

对于 Debian 系统来说,请使用 APT-GET 命令[4] 或者 APT 命令[5] 安装 fish shell。

对于 Debian 9 系统来说:

$ sudo wget -nv https://download.opensuse.org/repositories/shells:fish:release:3/Debian_9.0/Release.key -O Release.key$ sudo apt-key add - < Release.key$ sudo echo 'deb http://download.opensuse.org/repositories/shells:/fish:/release:/3/Debian_9.0/ /' > /etc/apt/sources.list.d/shells:fish:release:3.list$ sudo apt-get update$ sudo apt-get install fish

对于 Debian 8 系统来说:

$ sudo wget -nv https://download.opensuse.org/repositories/shells:fish:release:3/Debian_8.0/Release.key -O Release.key$ sudo apt-key add - < Release.key$ sudo echo 'deb http://download.opensuse.org/repositories/shells:/fish:/release:/3/Debian_8.0/ /' > /etc/apt/sources.list.d/shells:fish:release:3.list$ sudo apt-get update$ sudo apt-get install fish

对于 RHEL/CentOS 系统来说,请使用 YUM 命令[7] 安装 fish shell。

对于 RHEL 7 系统来说:

$ sudo yum-config-manager --add-repo https://download.opensuse.org/repositories/shells:/fish:/release:/3/RHEL_7/shells:fish:release:3.repo$ sudo yum install fish

对于 RHEL 6 系统来说:

$ sudo yum-config-manager --add-repo https://download.opensuse.org/repositories/shells:/fish:/release:/3/RedHat_RHEL-6/shells:fish:release:3.repo$ sudo yum install fish

对于 CentOS 7 系统来说:

$ sudo yum-config-manager --add-repo https://download.opensuse.org/repositories/shells:fish:release:2/CentOS_7/shells:fish:release:2.repo$ sudo yum install fish

对于 CentOS 6 系统来说:

$ sudo yum-config-manager --add-repo https://download.opensuse.org/repositories/shells:fish:release:2/CentOS_6/shells:fish:release:2.repo$ sudo yum install fish

对于 openSUSE Leap 系统来说,请使用 Zypper 命令[8] 安装 fish shell。

$ sudo zypper addrepo https://download.opensuse.org/repositories/shells:/fish:/release:/3/openSUSE_Leap_42.3/shells:fish:release:3.repo$ suod zypper refresh$ sudo zypper install fish

如何使用 Fish Shell ?

一旦你成功安装了 fish shell 。只需在你的终端上输入 fish ,它将自动从默认的 bash shell 切换到 fish shell 。

$ fish

226f58c24cdb064d6b74f9d3c0bd67a1.png

自动补全建议

当你在 fish shell 中键入任何命令时,它会在输入几个字母后以浅灰色自动建议一个命令。

744a3f52288419c0bfd31388e3a8d043.png

一旦你得到一个建议然后按下向右光标键(LCTT 译注:原文是左,错的)就能完成它而不是输入完整的命令。

15eb7c0d542a2718897e6ad96de82596.png

你可以在键入几个字母后立即按下向上光标键检索该命令以前的历史记录。它类似于 bash shell 的 CTRL+r 选项。

Tab 补全

如果你想查看给定命令是否还有其他可能性,那么在键入几个字母后,只需按一下 Tab 键即可。

f5eedb36709987819ada48b2406c3154.png

再次按 Tab 键可查看完整列表。

fe77ebeafe63df97e16f086720f989e5.png

语法高亮

fish 会进行语法高亮显示,你可以在终端中键入任何命令时看到。无效的命令被着色为 RED color 。

f0d56044d85f3682a8fcbf02aaa15537.png

同样的,有效的命令以不同的颜色显示。此外,当你键入有效的文件路径时,fish 会在其下面加下划线,如果路径无效,则不会显示下划线。

5aa0c711ef8701328b2eec2e38698cc5.png

基于 Web 的配置器

fish shell 中有一个很酷的功能,它允许我们通过网络浏览器设置颜色、提示符、功能、变量、历史和键绑定。

在终端上运行以下命令以启动 Web 配置界面。只需按下 Ctrl+c 即可退出。

$ fish_configWeb config started at 'file:///home/daygeek/.cache/fish/web_config-86ZF5P.html'. Hit enter to stop.qt5ct: using qt5ct plugin^CShutting down.

6629c80d85eefe87e544919e0c9cc972.png

手册页补全

其他 shell 支持可编程的补全,但只有 fish 可以通过解析已安装的手册页自动生成它们。

要使用该功能,请运行以下命令:

$ fish_update_completionsParsing man pages and writing completions to /home/daygeek/.local/share/fish/generated_completions/ 3466 / 3466 : zramctl.8.gz

如何将 Fish 设置为默认 shell

如果你想测试 fish shell 一段时间,你可以将 fish shell 设置为默认 shell,而不用每次都切换它。

要这样做,首先使用以下命令获取 Fish Shell 的位置。

$ whereis fishfish: /usr/bin/fish /etc/fish /usr/share/fish /usr/share/man/man1/fish.1.gz

通过运行以下命令将默认 shell 更改为 fish shell 。

$ chsh -s /usr/bin/fish

a670039dea864be03464d8f2642eeb80.png

提示:只需验证 Fish Shell 是否已添加到 /etc/shells 目录中。如果不是,则运行以下命令以附加它。

$ echo /usr/bin/fish | sudo tee -a /etc/shells

完成测试后,如果要返回 bash shell ,请使用以下命令。

暂时返回:

$ bash

永久返回:

$ chsh -s /bin/bash

via: https://www.2daygeek.com/linux-fish-shell-friendly-interactive-shell/

作者:Magesh Maruthamuthu[10] 选题:lujun9972 译者:zero-MK 校对:wxy

本文由 LCTT 原创编译,Linux中国 荣誉推出

d2e35bc786effa9716b82fc0b7b7c46f.png
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值