diff --git a/shell/src/parse.rs b/shell/src/parse.rs index 46740327e6..758d829a2e 100644 --- a/shell/src/parse.rs +++ b/shell/src/parse.rs @@ -904,11 +904,13 @@ fn parse_line_inner( } '"' if state.last_ch != '\\' => { let arg_str = read_string(jobs, chars)?; + let resolved = arg_str.resolve_arg(jobs)?.to_string_lossy().to_string(); // Single quote in token to avoid future expansions in string. + // Escape any literal single quotes in the content with '\'' so + // they survive the downstream expansion pipeline (expand_braces, + // expand_params_comms, expand_globs, strip_quotes). state.token().push('\''); - state - .token() - .push_str(&arg_str.resolve_arg(jobs)?.to_string_lossy()); + state.token().push_str(&resolved.replace('\'', "'\\''")); state.token().push('\''); state.last_ch = ch; } diff --git a/slosh_lib/src/lib.rs b/slosh_lib/src/lib.rs index 4503990a66..59247e0d92 100644 --- a/slosh_lib/src/lib.rs +++ b/slosh_lib/src/lib.rs @@ -650,6 +650,7 @@ pub fn run_slosh(modify_vm: impl FnOnce(&mut SloshVm)) -> i32 { status = run_shell_with_stdin(); } } else if let Some(mut command) = config.command { + load_core_slosh(); for a in &config.args { command.push(' '); command.push_str(a);