Skip to content

File redirections are not well scoped to an expression #17604

Closed
nushell/nushell.github.io
#2200

Description

@augu5te

Bug report form

  • I have done a basic search of the issue tracker to find any existing issues that are similar.
  • I have checked that my version is at least the latest stable release available via my installation method.

Describe the bug

The doc said:

Note that file redirections are scoped to an expression and apply to all external commands in the
expression. In the example below, out.txt will contain hello\nworld:

But only last commands seems redirected
Relate closed issue : #15326

How to reproduce

let text = "hello\nworld"
($text | head -n 1; $text | tail -n 1) o> out.txt
hello
cat out.txt
world

Expected behavior

 cat out.txt
hello
world

Configuration

key value
version 0.110.0
major 0
minor 110
patch 0
branch
commit_hash d40e191
build_os linux-x86_64
build_target x86_64-unknown-linux-musl
rust_version rustc 1.90.0 (1159e78c4 2025-09-14)
rust_channel 1.90.0-x86_64-unknown-linux-gnu
cargo_version cargo 1.90.0 (840b83a10 2025-07-30)
build_time 2026-01-18 02:06:38 +00:00
build_rust_channel release
allocator standard
features default, mcp, network, plugin, rustls-tls, sqlite, static-link-openssl, trash-support
installed_plugins
experimental_options example=false, reorder-cell-paths=true, pipefail=false, enforce-runtime-annotations=false

Activity

  1. added
    status:needs-triage
    on Feb 19, 2026
  2. fdncred commented on Feb 19, 2026

    @fdncred
    Contributor

    I think the only reason that you see hello is because head and tail circumvent the pipeline and printing things themselves. I think if you make this into a nushell command you'll see that only the last thing in the pipeline produces an output.

    ❯ let text = "hello\nworld"
    ❯ $text | split row "\n" | first
    hello
    ❯ $text | split row "\n" | last
    world
    ❯ $text | split row "\n" | first; $text | split row "\n" | last
    world
    ❯ ($text | split row "\n" | first; $text | split row "\n" | last)
    world
    ❯ ($text | split row "\n" | first; $text | split row "\n" | last) o> out.txt
    ❯ open out.txt
    world

    so nushell seems to behave consistently.

    However, this example seems wrong to me because nushell would be printing output multiple times in the pipeline, which hasn't been supported in a long time. Maybe this section of the docs is old? Is it possible I'm wrong and this is a regression? We'll have to wait and see what others think.

    Image
  3. added a commit that references this issue on Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:needs-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions