Skip to content

Commit 0af10d7

Browse files
hyperpolymathclaude
andcommitted
fix(shell): expand command subs in nested contexts and assignments
- Fix expand_command_substitution to use expand_with_command_sub for args (supports nested command subs) - Fix Assignment to use expand_with_command_sub (supports VAR=$(cmd)) - Fix Export to use expand_with_command_sub (supports export VAR=$(cmd)) Now working correctly: - Nested command subs: echo $(outer $(inner)) → "outer inner" - Variable assignment: VAR=$(pwd); echo $VAR → correct path - Export with command sub: export PATH=$(pwd):$PATH All 128 tests still passing. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 0bd6ed4 commit 0af10d7

4 files changed

Lines changed: 9 additions & 8 deletions

File tree

impl/rust-cli/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

impl/rust-cli/src/executable.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ impl ExecutableCommand for Command {
349349

350350
// Variable assignment
351351
Command::Assignment { name, value } => {
352-
// Expand variables in the value
353-
let expanded_value = crate::parser::expand_variables(value, state);
352+
// Expand variables and command substitutions in the value
353+
let expanded_value = crate::parser::expand_with_command_sub(value, state)?;
354354
state.set_variable(name, expanded_value);
355355
Ok(ExecutionResult::Success)
356356
}
@@ -359,8 +359,8 @@ impl ExecutableCommand for Command {
359359
Command::Export { name, value } => {
360360
if let Some(val) = value {
361361
// export VAR=value
362-
// Expand variables in the value
363-
let expanded_value = crate::parser::expand_variables(val, state);
362+
// Expand variables and command substitutions in the value
363+
let expanded_value = crate::parser::expand_with_command_sub(val, state)?;
364364
state.set_variable(name, expanded_value);
365365
state.export_variable(name);
366366
} else {

impl/rust-cli/src/parser.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,11 +1146,12 @@ pub fn expand_command_substitution(cmd: &str, state: &mut crate::state::ShellSta
11461146
process_cmd.stdout(Stdio::piped());
11471147
process_cmd.stderr(Stdio::null());
11481148

1149-
// Expand variables in args before execution
1150-
let expanded_args: Vec<String> = args
1149+
// Expand variables and command substitutions in args before execution
1150+
let expanded_args: Result<Vec<String>> = args
11511151
.iter()
1152-
.map(|arg| expand_variables(arg, state))
1152+
.map(|arg| expand_with_command_sub(arg, state))
11531153
.collect();
1154+
let expanded_args = expanded_args?;
11541155

11551156
process_cmd.args(&expanded_args);
11561157

impl/rust-cli/target/debug/vsh

214 KB
Binary file not shown.

0 commit comments

Comments
 (0)