Repository navigation
Description
Checks
- I have updated to the latest minor and patch version of Strands Shell (built from
55d7816;main@c28e1fbonly addswhoamion 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=0bash 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.
Activity
strandly-the-agent commentedon Nov 21, 2026
Two more for this list, found while reviewing #354:
touchandlscontinue past one failing operand but stop at the second. The description above saystouchis fine; that only holds for a single failure.main@dbb6189)touch nodir/a nodir/b cnodir/aonly,cnot created,rc=1ccreated,rc=1echo a > f; ls nope1 nope2 fnope1only,fnot listed,rc=1flisted,rc=2Cause
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 failureio::stderr()?returns an error, the command ends there, and the shell can't print that error either because stderr is already gone.rm.rsavoids this by taking stderr once and reusing it.