Skip to content

[BUG] A double-quoted empty word ("") is dropped from a command's arguments #299

Closed
strands-agents/box
#547

Description

@strandly-the-agent

Checks

  • I have updated to the latest minor and patch version of Strands Shell (built from main @ 5f80040)
  • 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

main @ 5f80040 (crate 0.12.1)

Language Runtime Version

Rust 1.100.0

Operating System

Linux 6.1 (aarch64)

Installation Method

built from source

Steps to Reproduce

strands-shell -c 'f(){ echo $#; }; f "" x; f '"''"' x; x=""; f "$x" y; printf "[%s]" "" x; echo'

Expected Behavior

Same as bash/POSIX sh: a quoted empty word is kept as an empty argument.

2
2
2
[][x]

Actual Behavior

1
2
2
[x]

Only the literal "" word is dropped; '' and "$x" (empty) are kept. Commands then see shifted arguments, e.g. tac -s "" f (from PR #287) fails with missing argument for option '-s', and tac -s "" x f silently uses x as the separator.

Additional Context

Found while reviewing #287; not caused by it (that PR only adds src/commands/tac.rs).

Possible Solution

"" parses to WordPart::DoubleQuoted(vec![]). In expand_part_split (src/exec.rs:587-591 on 5f80040), the DoubleQuoted arm loops over zero parts, so it never calls Segment::push and has_nonsplit stays false. ifs_split (src/exec.rs:637-641) then returns no field for the empty buffer. '' survives because the SingleQuoted arm (src/exec.rs:508-510) always pushes, which sets has_nonsplit.

I tried this patch locally. It fixes the repro above, and "$@" with no positional args still expands to zero words. I did not run the full test suite with it.

WordPart::DoubleQuoted(parts) => {
    if parts.is_empty() {
        segments.last_mut().unwrap().push("", false, false);
    }
    for p in parts {

Related Issues

#287, possibly related to #243

Activity

  1. added
    bug
    and removed
    bug
    on Nov 13, 2026
  2. ikenyal commented on Nov 17, 2026

    @ikenyal
    Contributor

    I'd like to work on this. I'll preserve literal empty double-quoted arguments and add regression coverage, including the case where "$@" with no positional parameters must still expand to no arguments.

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

    No labels
    No labels

    Type

    No type

    Fields

    Language

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions