Skip to content

[BUG] File commands stop at the first operand that fails (cat missing f prints nothing for f) #335

Open

Description

@strandly-the-agent

Checks

  • I have updated to the latest minor and patch version of Strands Shell (built from 55d7816; main @ c28e1fb only adds whoami on top)
  • 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

55d7816 (--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

Each line is a separate strands-shell -c '...' run in an empty directory.

echo body > f; cat missing f; echo "rc=$?"
echo y | tee nodir/a out >/dev/null; echo "rc=$?"; cat out
mkdir nodir/a b; echo "rc=$?"; ls
mkdir e1; rmdir missing e1; echo "rc=$?"; ls
touch f; chmod 600 missing f; echo "rc=$?"; ls -l f
mkdir d; echo hi > f; cp missing f d; echo "rc=$?"; ls d
echo hi > f; sed -i s/h/H/ missing f; echo "rc=$?"; cat f
echo hi > f; wc -l missing f; echo "rc=$?"

Expected Behavior

Same as coreutils: report the operand that failed, carry on with the rest, and exit non-zero at the end.

Command bash 5.2.15 / coreutils
cat missing f error for missing, prints body, rc=1
tee nodir/a out error for nodir/a, out holds y, rc=1
mkdir nodir/a b error for nodir/a, b is created, rc=1
rmdir missing e1 error for missing, e1 is removed, rc=1
chmod 600 missing f error for missing, f becomes -rw-------, rc=1
cp missing f d error for missing, d/f is created, rc=1
sed -i s/h/H/ missing f error for missing, f holds Hi
wc -l missing f error for missing, prints 1 f and 1 total, rc=1

Actual Behavior

Each command prints the error for the first failing operand, exits 1, and does nothing for the operands after it: cat prints nothing, out is never written, b is not created, e1 stays, f keeps mode -rw-r--r--, d stays empty, f still holds hi, and wc prints no counts.

tee also stops copying to stdout, so in a pipeline the data is lost with status 0:

$ strands-shell -c "echo x | tee '' | cat; echo rc=\$?"
strands-shell: tee: is a directory
rc=0

bash prints the error, then x.

Additional Context

Found while reviewing #332. It is not caused by that PR: the results above are identical on its base 55d7816 and its head 3abe869. Once #299 is fixed this is easier to hit, because cmd "$unset" other now passes an empty operand that fails first, where the word used to be dropped. For example mkdir -p "$D" build with D unset no longer creates build.

rm and touch already collect errors and continue. I ran debug builds through -c against the default virtual filesystem, and did not test other commands that take several file operands.

Possible Solution

Each of these loops returns on the first error with ?: src/commands/cat.rs:59, tee.rs:33, mkdir.rs:56 and :59, rmdir.rs:25, chmod.rs:102, sed.rs:516, wc.rs:97, and the copy loop in cp.rs. src/commands/rm.rs shows the other shape: it reports each failure, sets the exit code and continues. I have not written or tested a fix.

Related Issues

#332, #299

Activity

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

    @strandly-the-agent
    CollaboratorAuthor

    Two more for this list, found while reviewing #354: touch and ls continue past one failing operand but stop at the second. The description above says touch is fine; that only holds for a single failure.

    Command (on main @ dbb6189) strands-shell bash 5.2.15 / coreutils 9.1
    touch nodir/a nodir/b c error for nodir/a only, c not created, rc=1 both errors, c created, rc=1
    echo a > f; ls nope1 nope2 f error for nope1 only, f not listed, rc=1 both errors, f listed, rc=2
    Cause

    Both take stderr inside the loop (src/commands/touch.rs:94, src/commands/ls.rs:320). A process can take a descriptor only once, so on the second failure io::stderr()? returns an error, the command ends there, and the shell can't print that error either because stderr is already gone. rm.rs avoids this by taking stderr once and reusing it.

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