Repository: nushell/nushell
File: crates/nu-command/src/system/run_external.rs (Rust)

Code before:
                    .to_uppercase();
                ext == "PS1"
            } else {
                false
            }
        } else {
            false
        };

        // Find the absolute path to the executable. On Windows, set the
        // executable to "cmd.exe" if it's a CMD internal command. If the
        // command is not found, display a helpful error message.
        let executable = if cfg!(windows)
            && (is_cmd_internal_command(&name_str) || potential_nuscript_in_windows)
        {
            PathBuf::from("cmd.exe")
        } else if cfg!(windows) && potential_powershell_script {
            // If we're on Windows and we're trying to run a PowerShell script, we'll use
            // `powershell.exe` to run it. We shouldn't have to check for powershell.exe because
            // it's automatically installed on all modern windows systems.
            PathBuf::from("powershell.exe")
        } else {
            // Determine the PATH to be used and then use `which` to find it - though this has no
            // effect if it's an absolute path already
            let paths = nu_engine::env::path_str(engine_state, stack, call.head)?;
            let Some(executable) = which(expanded_name.clone(), &paths, cwd.as_ref()) else {
                return Err(command_not_found(&name_str, call.head, engine_state, stack));
            };
            executable
        };

        // Create the command.
        let mut command = std::process::Command::new(executable);

        // Configure PWD.
        command.current_dir(cwd);

        // Configure environment variables.
        let envs = env_to_strings(engine_state, stack)?;
        command.env_clear();
        command.envs(envs);

        // Configure args.
        let args = eval_arguments_from_call(engine_state, stack, call)?;
        #[cfg(windows)]
        if is_cmd_internal_command(&name_str) || potential_nuscript_in_windows {
            // The /D flag disables execution of AutoRun commands from registry.
            // The /C flag followed by a command name instructs CMD to execute
            // that command and quit.
            command.args(["/D", "/C", &expanded_name.to_string_lossy()]);
            for arg in &args {

Review comment (suggestion):
It's not need to clone the variable
```suggestion
            let Some(executable) = which(&expanded_name, &paths, cwd.as_ref()) else {
```

Code after:
                    .to_uppercase();
                ext == "PS1"
            } else {
                false
            }
        } else {
            false
        };

        // Find the absolute path to the executable. On Windows, set the
        // executable to "cmd.exe" if it's a CMD internal command. If the
        // command is not found, display a helpful error message.
        let executable = if cfg!(windows)
            && (is_cmd_internal_command(&name_str) || potential_nuscript_in_windows)
        {
            PathBuf::from("cmd.exe")
        } else if cfg!(windows) && potential_powershell_script {
            // If we're on Windows and we're trying to run a PowerShell script, we'll use
            // `powershell.exe` to run it. We shouldn't have to check for powershell.exe because
            // it's automatically installed on all modern windows systems.
            PathBuf::from("powershell.exe")
        } else {
            // Determine the PATH to be used and then use `which` to find it - though this has no
            // effect if it's an absolute path already
            let paths = nu_engine::env::path_str(engine_state, stack, call.head)?;
            let Some(executable) = which(&expanded_name, &paths, cwd.as_ref()) else {
                return Err(command_not_found(&name_str, call.head, engine_state, stack));
            };
            executable
        };

        // Create the command.
        let mut command = std::process::Command::new(executable);

        // Configure PWD.
        command.current_dir(cwd);

        // Configure environment variables.
        let envs = env_to_strings(engine_state, stack)?;
        command.env_clear();
        command.envs(envs);

        // Configure args.
        let args = eval_arguments_from_call(engine_state, stack, call)?;
        #[cfg(windows)]
        if is_cmd_internal_command(&name_str) || potential_nuscript_in_windows {
            // The /D flag disables execution of AutoRun commands from registry.
            // The /C flag followed by a command name instructs CMD to execute
            // that command and quit.
            command.args(["/D", "/C", &expanded_name.to_string_lossy()]);
            for arg in &args {