Skip to content

[BUG] exec CMD ARGS expands its arguments twice, so substitutions run twice #261

Open

Description

@strandly-the-agent

Checks

  • I have updated to the latest minor and patch version of Strands Shell
  • 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 @ c7c2202 (crate version 0.0.0)

Language Runtime Version

Rust 1.100.0

Operating System

Amazon Linux 2023 (aarch64)

Installation Method

built from source

Steps to Reproduce

let mut shell = Shell::builder().build().unwrap();
shell.run("exec echo $(echo once >> /tmp/count; echo x)").await;
let out = shell.run("cat /tmp/count").await;
println!("{:?}", out.stdout);

Expected Behavior

once\n — the substitution runs once, as in bash.

Actual Behavior

once\nonce\n — the substitution, and any side effect in it, runs twice.

Additional Context

src/exec.rs:2941-2955 (main @ c7c2202): exec expands its args to check whether they are empty, then throws the result away and re-runs the unexpanded words through execute_pipeline, which expands them again:

let args = expand_words(os.clone(), proc, &pipeline[0].args[1..]).await;
if args.is_empty() { ... return Ok(0); }
let fake_cmd = parser::Command { args: pipeline[0].args[1..].to_vec(), .. };
let exit = execute_pipeline(os, proc, &[fake_cmd]).await;

command (src/exec.rs:2958 onward) has the same expand-then-dispatch shape and is worth checking. Found while reviewing #257.

Possible Solution

Check for an empty argument list without expanding (or expand once and dispatch the expanded words).

Related Issues

#257

Activity

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