Skip to content

[BUG] cmd &>file runs cmd in the background and redirects nothing (ls /missing &>/dev/null; echo $? prints 0) #369

Open

Description

@strandly-the-agent

Checks

  • I have updated to the latest minor and patch version of Strands Shell (built from main @ dbb6189)
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Binding

Rust

Strands Shell Version

dbb6189 (--version prints 0.0.0)

Language Runtime Version

Rust 1.100.0

Operating System

Linux 6.18 (aarch64)

Installation Method

built from source

Steps to Reproduce

strands-shell -c 'ls /nonexistent-dir &>/dev/null; echo "rc=$?"'
strands-shell -c 'echo hi &>out.txt; wait; echo "file=[$(cat out.txt)]"'

Expected Behavior

Same as bash: &>file sends stdout and stderr to the file.

rc=2
file=[hi]

with nothing on stderr.

Actual Behavior

rc=0
hi
file=[]

and ls: cannot access '/nonexistent-dir': No such file or directory on stderr.

Additional Context

The output is what cmd & >file would give: the command's output isn't redirected, $? is 0 instead of the command's status, and the file is created empty. I haven't read the parser to confirm that is how &> is split.

cmd >/dev/null 2>&1 works: ls /nonexistent-dir >/dev/null 2>&1; echo "rc=$?" prints rc=2 with nothing on stderr.

cmd &>/dev/null is a common way to silence a command and then check its status, so a script gets the wrong status and the output it tried to hide.

Found while reviewing #348; it is not caused by that PR. The results are the same on main @ dbb6189 and on #348's head 9ef3e56. I ran debug builds through -c only and compared with bash 5.2.15.

Possible Solution

Not investigated.

Related Issues

#207

Activity

  1. added
    bug
    on Nov 21, 2026
  2. strandly-the-agent commented on Nov 21, 2026

    @strandly-the-agent
    CollaboratorAuthor

    The other bash spelling of this, cmd >&file, also fails, in a different way: the redirect is rejected and the command doesn't run. Worth fixing together.

    strands-shell -c 'echo hi >&out.txt; echo "rc=$?"'

    bash writes hi to out.txt and prints rc=0. main @ dbb6189 prints strands-shell: out.txt: bad file descriptor and rc=1, and creates no file. src/exec.rs:1772-1774 parses the word after >& as an fd number and has no fallback for a file name.

    Found while reviewing #346. Once that merges, command -v X >&/dev/null takes this path as well (as type X >&/dev/null already does), so if command -v cd >&/dev/null; then … takes the else branch.

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

    bug

    Type

    Fields

    Language

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions