nushell 命令详解

| 选择喜欢的代码风格  

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

nushell 命令安装:


-bash/zsh: nushell command not not found

# Windows (WSL2)
winget install nushell

-------------------------------------------------------------
Winget # Install to user scope (by default).

- Machine scope installation: winget install nushell --scope machine # (Run as admin).
- Machine scope upgrade: winget update nushell
- User scope installation: winget install nushell or winget install nushell --scope user
- User scope upgrade: Due to winget-cli issue #3011, running winget update nushell will unexpectedly install the latest version to C:\Program Files\nu. To work around this, run winget install nushell again to install the latest version in the user scope.
-------------------------------------------------------------

Chocolatey (choco install nushell)

-------------------------------------------------------------

Scoop (scoop install nu)

-------------------------------------------------------------

# 上述三种方法安装后,命令行打入 nu,启动 Nu!

# Debian
curl -fsSL https://apt.fury.io/nushell/gpg.key | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/fury-nushell.gpg
echo "deb https://apt.fury.io/nushell/ /" | sudo tee /etc/apt/sources.list.d/fury.list
sudo apt update
sudo apt install nushell

# For RedHat/Fedora & Rocky Linux:
echo "[gemfury-nushell]
name=Gemfury Nushell Repo
baseurl=https://yum.fury.io/nushell/
enabled=1
gpgcheck=0
gpgkey=https://yum.fury.io/nushell/gpg.key" | sudo tee /etc/yum.repos.d/fury-nushell.repo
sudo dnf install -y nushell

# For Alpine Linux:
echo "https://alpine.fury.io/nushell/" | tee -a /etc/apk/repositories
apk update
apk add --allow-untrusted nushell

# Cross Platform installation:
npm (npm install -g nushell Note that nu plugins are not included if you install in this way)

# Docker Container Images
docker run -it --rm ghcr.io/nushell/nushell:<version>-<distro>

docker run --rm \
    -v $(pwd):/work \
    ghcr.io/nushell/nushell:latest-alpine \
    "/work/script.nu"

# MacOS
brew install nushell


Nushell

Nix profile:

nix profile install nixpkgs#nushell

nushell 命令补充说明:



Nu 操作的是类型化数据,因此它能捕获其他 shell 无法捕获的错误。当出现问题时,Nu 会准确地告诉你问题出在哪里以及原因:

Nushell 项目的目标是将 Unix Shell 的理念:即使用管道将简单的命令连接在一起 融入现代开发风格。因此,Nushell 并非仅仅是一个 Shell 或一门编程语言,而是通过将丰富的编程语言和功能齐全的 Shell 整合到一个包中,将两者完美结合。

Nu 汲取了许多熟悉领域的灵感:像 Bash 这样的传统 Shell、像 PowerShell 这样的基于对象的 Shell、像 TypeScript 这样的渐进式类型语言、函数式编程、系统编程等等。但 Nu 并非试图成为万能的 Shell,而是专注于做好以下几件事:

  • Nushell 成为一个灵活的跨平台 Shell,并兼具现代风格
  • Nu 以现代编程语言的方式解决问题,并适应您的数据结构
  • Nu 提供清晰的错误消息和简洁的 IDE 支持

nushell 命令语法:


nu {flags} (script file) ...(script args)

nushell 命令参数:


script file <path>: name of the optional script file to run (optional)
...script args <string>: parameters to the script file

nushell 命令选项:


-h, --help: Display the help message for this command
-c, --commands <string>: run the given commands and then exit
-e, --execute <string>: run the given commands and then enter an interactive shell
-I, --include-path <string>: set the NU_LIB_DIRS for the given script (delimited by char record_sep (''))
-i, --interactive: start as an interactive shell
-l, --login: start as a login shell
-m, --table-mode <string>: the table mode to use. rounded is default.
--error-style <string>: the error style to use (fancy or plain). default: fancy
--no-newline: print the result for --commands(-c) without a newline
-n, --no-config-file: start with no config file and no env file
--no-history: disable reading and writing to command history
--no-std-lib: start with no standard library
-t, --threads <int>: threads to use for parallel commands
-v, --version: print the version
--config <path>: start with an alternate config file
--env-config <path>: start with an alternate environment config file
--lsp: start nu's language server protocol
--ide-goto-def <int>: go to the definition of the item at the given position
--ide-hover <int>: give information about the item at the given position
--ide-complete <int>: list completions for the item at the given position
--ide-check <int>: run a diagnostic check on the given source and limit number of errors returned to provided number
--ide-ast: generate the ast on the given source
--plugin-config <path>: start with an alternate plugin registry file
--plugins <list<path>>: list of plugin executable files to load, separately from the registry file
--log-level <string>: log level for diagnostic logs (error, warn, info, debug, trace). Off by default
--log-target <string>: set the target for the log to output. stdout, stderr(default), mixed or file
--log-include <list<string>>: set the Rust module prefixes to include in the log output. default: [nu]
--log-exclude <list<string>>: set the Rust module prefixes to exclude from the log output
--stdin: redirect standard input to a command (with -c) or a script file
--testbin <string>: run internal test binary
--experimental-options <list<string>>: enable or disable experimental options, use "all" to set all active options

nushell 命令实例:


nushell 的 describe 命令返回数据值的类型:

42 | describe
# => int

10 / 2
# => 5
5 | describe
# => int

2.5 / 5.0
# => 0.5

与许多语言一样,Nushell 提供了多种指定字符串值的方法和许多用于处理字符串的命令。

let audience: string = "World"
$"Hello, ($audience)"

# => Hello, World

nushell 关于 Date 类型的一些示例:

date now
# => Sun, 17 Aug 2025 22:14:27 +0800 (now)

date now | format date '%s'
# => 1755440087

3.5day
# => 3day 12hr
------------------------
# 注意 3.5 和 day 之间,不要有空格,否则报错:
3.5 day
# => Error: nu::parser::parse_mismatch

  × Parse mismatch during operation.
   ╭─[entry #72:1:5]
 1 │ 3.5 day
   ·     ─┬─
   ·      ╰── expected operator
   ╰────

nushell 关于 FileSize 类型示例:

0.5kB
# => 500 B

1GiB / 1B
# => 1073741824

(1GiB / 1B) == 2 ** 30
# => true

nushell 的 Range 类型:

1..5
# => ╭───┬───╮
# => │ 0 │ 1 │
# => │ 1 │ 2 │
# => │ 2 │ 3 │
# => │ 3 │ 4 │
# => │ 4 │ 5 │
# => ╰───┴───╯

------------------------------------------
# nu 输出偶数
------------------------------------------

2..4..20
╭───┬────╮
│ 0 │  2 │
│ 1 │  4 │
│ 2 │  6 │
│ 3 │  8 │
│ 4 │ 10 │
│ 5 │ 12 │
│ 6 │ 14 │
│ 7 │ 16 │
│ 8 │ 18 │
│ 9 │ 20 │
╰───┴────╯

------------------------------------------
# nu 输出顺序字母
------------------------------------------

> seq char a e
╭───┬───╮
│ 0 │ a │
│ 1 │ b │
│ 2 │ c │
│ 3 │ d │
│ 4 │ e │
╰───┴───╯

> seq char a e | str join '|'
a|b|c|d|e

nushell 的 chart 能力,比如直方图:

[1 2 3 1 1 1 2 2 1 1] | histogram --percentage-type relative
╭───┬───────┬───────┬──────────┬────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ # │ value │ count │ quantile │ percentage │                                              frequency                                               │
├───┼───────┼───────┼──────────┼────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ 0 │     1 │     6 │     1.00 │ 100.00%    │ **************************************************************************************************** │
│ 1 │     2 │     3 │     0.50 │ 50.00%     │ **************************************************                                                   │
│ 2 │     3 │     1 │     0.17 │ 16.67%     │ ****************                                                                                     │
╰───┴───────┴───────┴──────────┴────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────╯

nushell 操作网络的一些方法,如 GET / POST 等:

# Get content from baidu.com with default verb
> http https://www.baidu.com 

# Post content to baidu.com with default verb
> http https://www.baidu.com


# Get content from baidu.com with explicit verb
> http get https://www.baidu.com

nushell 命令扩展阅读:


 

CommandNotFound ⚡️ 坑否 - 其他频道扩展阅读:




nushell 命令评论

共收录到 545Linux 命令