返回文章列表文章索引阅读全文
STARBLOG / 阅读手记
Linux

Still using bash in this day and age? Out-of-the-box modern shells: fish, nu, elvish

Fish works out of the box, with really nice smart completions and colors? Nushell handles data like SQL, everything is an object, but a steep learning curve? Elvish is like a programming language, tightly logical, niche community? Why bother tinkering—just switch shells?

曦远 (DealiAxy)约 19 分钟
目录20 个章节

Preface

Linux servers generally default to bash as the shell, which isn't very smart. You can use a modern shell to improve the command-line experience.

zsh is a decent choice, but it's ugly by default and pairing it with Oh My Zsh is a hassle. This article covers installing and getting started with some of the newer, out-of-the-box shells.

If you use the chsh command to change the default login shell (Login Shell), some system scripts or automation tasks that depend on Bash-specific environment variables (such as settings in /etc/profile) may error out because they can't find the Bash environment.

Approach: launch the modern shell from within Bash.

Which of the three modern shells is strongest?

Each of the three has its own character—pick according to taste:

🐟 Fish

(Friendly Interactive SHell) The most hassle-free "all-rounder"

  • Features: Ready out of the box. Built-in syntax highlighting, smart completions (based on your history and man pages), and very nice colors.
  • Verdict: Easiest to pick up. If you don't want to mess with config and just want to get stronger the moment you install it, Fish is the first choice.
  • Downsides: Although parts of the engine were rewritten starting with 4.0, it still isn't POSIX-compatible (for example, the VAR=val cmd syntax wasn't supported in older Fish).

🦀 Nushell

(Nu) The "futurist" that handles data like SQL

  • Features: Everything is an object. In Nu, ls doesn't return a string of text—it returns a table. You can write things like ls | where size > 10mb.
  • Verdict: The geekiest and most fun. It's not just a shell—it's more like a modern data-processing tool. If you often deal with JSON, CSV, or large batches of logs, it'll send you flying.
  • Downsides: Steeper learning curve; some traditional command syntax takes getting used to.

🧝 Elvish

The programmer's "elegant language"

  • Features: It tries to turn the shell into a real, powerful programming language. Supports complex structures (Map, List), and even has its own package manager.
  • Verdict: The most solid, with the tightest logic. Suited for people who find Bash script syntax "hellish" and want to write scripts with a modern programming mindset.
  • Downsides: Relatively smaller community ecosystem.

Tips

Nushell and Elvish are both cross-platform, meaning you can get a consistent experience on Windows, macOS, and Linux. As for Fish, I've only used it on Linux and haven't looked into whether it works on other systems.

Fish

Installing Fish

# Ubuntu/Debian
sudo apt update && sudo apt install fish -y

Installing Fisher (plugin manager)

This is currently the best tool for the job; I recommend installing it first. Run the following in fish:

curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source && fisher install jorgebucaran/fisher

Configuring the launch logic

Add the following logic at the end of your ~/.bashrc file:

# 检查是否是交互式会话,且目标 shell 存在
if [[ $- == *i* ]] && command -v fish >/dev/null 2>&1; then
    exec fish
fi
  • [[ $- == \*i\* ]]: Makes sure this only fires in an interactive command line (when you're operating it yourself). If a script is running without a terminal, it won't launch, so you don't break automation.
  • exec: This word is crucial. It replaces the current process with a new one, so when you exit fish, the connection closes directly instead of dropping you back into a blank bash.

A few fun plugins/themes I recommend

Once Fisher is installed, you can run these commands to install some experience-boosting gems:

  1. Pure (a clean, beautiful theme) fisher install pure-fish/pure A very clean, modern Prompt theme with excellent visuals.
  2. Done (task-complete notifications) fisher install franciscolourenco/done If you run a long-running command (like a compile or backup), when it finishes it will send you a notification even if you're looking at another window.
  3. Bass (Bash script compatibility) fisher install edc/bass This one matters most for you! Because Fish isn't compatible with Bash syntax, commands like source /etc/profile will error in Fish. After installing Bass, you can write bass source /etc/profile and it will handle the compatibility for you.

Quick tips

  • Web UI configuration: Type fish_config in the Fish terminal. It will automatically pop up a browser page where you can click around to change color schemes and functions—very intuitive.
  • Smart completions: Fish completions are based on your history. When you type the first few letters of a command, it shows a suggestion in gray; press the right arrow key (→) or Ctrl + F to fill it in.

I want them all

Nushell (Nu)

Data processing's "higher-dimensional strike"

Nushell is currently the most-discussed, most hardcore modern shell in the community. Its core logic is: everything is structured data.

Why is it fun?

In a traditional shell, ls outputs a string. If you want to filter by file size, you have to painfully slice that string with grep, awk, and cut. In Nushell, ls outputs an in-memory table.

Give it a try:

ls | where size > 10mb | sort-by type

It will filter files larger than 10MB and sort by type, just like SQL, and the output is still a neat table.

A JSON/YAML powerhouse: If you have a config.json, in Nu you just need:

open config.json | get database.port

It pulls the value out directly—no need to install jq at all.

Installation

https://www.nushell.sh/book/installation.html

Nushell is written in Rust and is very fast. You can download the binary directly or use a package manager.

wget -qO- https://apt.fury.io/nushell/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/fury-nushell.gpg
echo "deb [signed-by=/etc/apt/keyrings/fury-nushell.gpg] https://apt.fury.io/nushell/ /" | sudo tee /etc/apt/sources.list.d/fury-nushell.list
sudo apt update
sudo apt install nushell

Elvish

The programmer's "Swiss army knife"

Elvish (elvish language) takes the extreme robustness and programming-friendly route. Its author is Chinese developer Qi Xiao, and the design philosophy is very rigorous.

Why is it fun?

  • Pipes that don't break: In Bash, pipes carry a byte stream; in Elvish, pipes can carry complex data structures (lists, dictionaries).
  • Built-in file manager: The history search UI with Ctrl+R is quite gorgeous; Ctrl+L enters a floating file-navigation mode similar to ranger, so you can pick files right in the shell.
  • Extremely consistent syntax: It completely abandons Bash's fragmented syntax (like the difference between [ and [[); writing its scripts feels like writing a modern programming language.

Installation

https://elv.sh/get/package-manager.html

sudo apt install elvish

Configuring the launch logic

Put a selector in ~/.bashrc.

Every time you log in it will ask which shell you want to use (personally I'd just go with fish—it works out of the box)

# 交互模式下询问你想进入哪个宇宙
if [[ $- == *i* ]]; then
    echo "Choose your shell: [1] Fish  [2] Nushell  [3] Elvish  [Any] Stay in Bash"
    read -n 1 -p "Select: " choice
    echo
    case $choice in
        1) exec fish ;;
        2) exec nu ;;
        3) exec elvish ;;
        *) echo "Welcome back to Bash." ;;
    esac
fi

_EOF_

Still using bash in this day and age? Out-of-the-box modern shells: fish, nu, elvish

本文作者:
程序设计实验室
版权声明:
本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!

相关文章

CentOS6安装Nginx,Linux编译安装Nginx

前言 最近笔者把一个django项目部署到一个新的服务器上,而这个服务器给的是CentOS6版本的系统,官方源很旧,yum管理器被运维搞坏了,没办法加载epel源,所以想要用nginx就只能自己编译安装咯~ 下载nginx代码 首先到Nginx的官网下载安装文件。 链接:http://nginx.org/ 我用的版本是:nginx-1.12.1.tar.gz 安装编译所需环境 安装gcc 安装 n

2022-06-17 · Linux · 约 1 分钟

你可能不知道的Linux死机重启方法

前言 不管在工作或者学习中,都可能遇到电脑死机的情况,如果直接强制关机或者切断电源可能会带来硬件的损坏,严重的可能导致数据丢失。 在学习中使用Linux经常遇到死机的情况,而且无法通过Alt+Ctrl+F[1-7]登陆,也无法通过ssh登陆。 更安全、底层的方法 按下Alt+Ctrl+SysReq(PrintScr键)一秒钟,保持Alt+Ctrl按下状态,松开PrintScr键; 保持按下Alt+

2022-06-17 · Linux · 约 1 分钟

讨论

共 0 条

良言一句三冬暖,恶语伤人六月寒。

加载评论中…