Skip to content

fix(shell): match bash on head -c, exec redirects, and read -d - #442

Closed
fengqiaoqu wants to merge 1 commit into
strands-agents:mainfrom
fengqiaoqu:fix/shell-stdin-bash-compat-440
Closed

fengqiaoqu wants to merge 1 commit into
strands-agents:mainfrom
fengqiaoqu:fix/shell-stdin-bash-compat-440

Conversation

@fengqiaoqu

Copy link
Copy Markdown
Contributor

Description

Since #397, stdin reaches the hosted Shell, and three behaviours still differ from bash.

  1. x=$(head -c 1); cat dropped the rest of stdin. head takes fd 0 out of the process and did not put the remaining reader back, so leftover bytes were discarded with it. After a head that read stdin, fd 0 is restored.
  2. exec < /dev/null with no command returned 0 and left stdin unchanged (there was a TODO for this). Those redirects are now applied to the current shell, so later commands see them.
  3. read -d '' did not parse -d. An empty delimiter is NUL, as in bash: the builtin reads until that byte or EOF, assigns what it read, trims trailing IFS, and returns 1 when EOF arrives before the delimiter.

The three cases in #440 are covered by tests in crates/shell/tests/shell_integration.rs. The local shell divergence is recorded in crates/shell/UPSTREAM.md.

Related Issues

Fixes #440

Type of Change

Bug fix

Testing

  • I ran the relevant suites (cargo test -p strands-shell --all-features: lib, integration (1345 passed), and doctests)
  • If I touched Rust, I ran cargo fmt --all and just clippy (the workspace recipe, including the vendored-shell lint allowances)

Not run: full workspace just test.

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR
  • My change is focused and reasonably small
  • I have added any necessary tests that prove my fix is effective
  • I have updated the documentation accordingly
  • My changes generate no new warnings

head -c left leftover stdin dropped, exec with no command ignored
redirects, and read did not implement -d. Restore the remaining
input after head, apply exec redirects to the shell, and treat an
empty -d delimiter as NUL.

Fixes strands-agents#440
@github-actions github-actions Bot added Area - Shell/Monty bug Something isn't working labels Nov 13, 2026
@ferdingler

Copy link
Copy Markdown
Collaborator

Thanks for digging into these! Box no longer vendors Shell since #414, it depends on upstream strands-agents/shell, so this has nowhere to land here anymore. I checked upstream and all three gaps are still there (head -c doesn't put stdin back, exec < with no command is still a TODO in src/exec.rs, and read has no -d), and no open upstream PR covers them. Could you re-file this against strands-agents/shell? Box picks it up on the next pin bump. Closing this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area - Shell/Monty bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shell: three stdin behaviours differ from bash

2 participants