nushell
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseUsing Nushell
使用Nushell
Nushell is a structured-data shell. Commands pass tables, records, and lists through pipelines - not text.
Two execution paths:
- MCP server: - persistent REPL (variables survive across calls)
mcp__nushell__evaluate - Bash tool: - one-shot (use single quotes for outer wrapper)
nu -c '<code>'
Nushell是一款结构化数据Shell。命令通过管道传递表格、记录和列表——而非文本。
两种执行路径:
- MCP服务器:- 持久化REPL(变量在多次调用间保留)
mcp__nushell__evaluate - Bash工具:- 单次执行(外层使用单引号包裹)
nu -c '<code>'
Critical Rules
关键规则
NEVER use bare in MCP stdio mode. Output will be lost (returns empty ). Use for stderr, or just return the value (implicit return).
print[]print -e "msg"String interpolation uses parentheses, NOT curly braces:
nu
undefined在MCP标准输入输出模式下,绝对不要使用裸命令。 输出会丢失(返回空)。如需输出到标准错误流,请使用,或直接返回值(隐式返回)。
print[]print -e "msg"字符串插值使用括号,而非大括号:
nu
undefinedWRONG: $"hello {$name}"
错误写法: $"hello {$name}"
CORRECT: $"hello ($name)"
正确写法: $"hello ($name)"
$"($env.HOME)/docs" $"2 + 2 = (2 + 2)" $"files: (ls | length)"
Gotcha: `$"(some text)"` errors - parens are evaluated as code. Escape literal parens: `\(text\)`.
**No bash syntax:** `cmd1; cmd2` not `&&`, `o+e>|` not `2>&1`, `$env.VAR` not `$VAR`, `(cmd)` not `$(cmd)`.$"($env.HOME)/docs" $"2 + 2 = (2 + 2)" $"files: (ls | length)"
注意:`$"(some text)"`会报错——括号内内容会被当作代码执行。若要使用字面括号,需转义:`\(text\)`。
**不支持Bash语法:** 应使用`cmd1; cmd2`而非`&&`,使用`o+e>|`而非`2>&1`,使用`$env.VAR`而非`$VAR`,使用`(cmd)`而非`$(cmd)`。Common Mistakes
常见错误
| Mistake | Fix |
|---|---|
| |
| |
| |
| |
| |
| Mutating in closure | Use |
| |
| Second |
| |
| Parsed as two pipeline stages. Use |
| 错误写法 | 修正方案 |
|---|---|
| |
MCP模式下使用 | 使用 |
| |
| |
| |
| 在闭包中修改数据 | 使用 |
使用 | 使用 |
| 第二个 |
| |
| 会被解析为两个管道阶段。使用 |
When to Use Nushell
Nushell适用场景
Always prefer Nushell for:
- Any structured data (JSON, YAML, TOML, CSV, Parquet, SQLite) - unifies all formats
- CLI tools with flags - pipe JSON output directly into Nushell for querying (e.g.
--json)^gh pr list --json title,state | from json - Ad-hoc data analysis and exploration - faster than Python setup
- Initial data science/analytics - histograms, tabular output, basic aggregations
- Polars plugin for large datasets - DataFrames without Python overhead
Use Bash only when: bash-specific tooling, MCP unavailable, or bash-syntax integrations.
以下场景优先使用Nushell:
- 处理任何结构化数据(JSON、YAML、TOML、CSV、Parquet、SQLite)——统一所有数据格式
- 支持参数的CLI工具——可将JSON输出直接传入Nushell进行查询(例如:
--json)^gh pr list --json title,state | from json - 临时数据分析与探索——比Python环境搭建更快捷
- 初始数据科学/分析——直方图、表格输出、基础聚合操作
- 处理大型数据集的Polars插件——无需Python开销的DataFrames
仅在以下场景使用Bash: 需要Bash专属工具、MCP不可用,或需集成Bash语法时。
Reference Files
参考文档
Read the relevant file(s) based on what you need:
| File | Read when you need... |
|---|---|
| commands.md | Command reference tables (filters, strings, conversions, filesystem, math, dates) |
| types-and-syntax.md | Type system, string types, operators, variables, control flow, cell-paths |
| data-analysis.md | Format conversion, HTTP, Polars, SQLite, aggregation patterns |
| advanced.md | Custom commands, modules, error handling, jobs, external commands, env config |
| bash-equivalents.md | Complete Bash-to-Nushell translation table |
| http-transport.md | Differences when using HTTP transport instead of stdio |
根据需求阅读对应文档:
| 文档 | 适用场景 |
|---|---|
| commands.md | 命令参考表(过滤器、字符串、转换、文件系统、数学、日期) |
| types-and-syntax.md | 类型系统、字符串类型、运算符、变量、控制流、单元格路径 |
| data-analysis.md | 格式转换、HTTP、Polars、SQLite、聚合模式 |
| advanced.md | 自定义命令、模块、错误处理、任务、外部命令、环境配置 |
| bash-equivalents.md | 完整的Bash到Nushell转换对照表 |
| http-transport.md | 使用HTTP传输替代标准输入输出的差异说明 |
MCP Server Quick Notes
MCP服务器快速说明
- - run code;
mcp__nushell__evaluate- discover;mcp__nushell__list_commands- helpmcp__nushell__command_help - State persists between calls. stores prior results (access
$history, etc.)$history.0 - Use or
| to textfor large outputs. Use| to jsonfor color removal.ansi strip
- - 运行代码;
mcp__nushell__evaluate- 发现命令;mcp__nushell__list_commands- 查看帮助mcp__nushell__command_help - 调用间状态会保留。存储之前的执行结果(可通过
$history等访问)$history.0 - 处理大输出时使用或
| to text。使用| to json移除颜色标记。ansi strip