From adf565360cc2fb844d965fd9195b363626e400d8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 19:30:29 +0000 Subject: [PATCH 1/5] Initial plan From 2071c56b453a10f0e832b9a4359378d33af4c4b7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 19:33:01 +0000 Subject: [PATCH 2/5] Use SHELL environment variable as fallback before /bin/bash Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/shell.feature | 22 ++++++++++++++++++++++ src/WP_CLI/Shell/REPL.php | 2 ++ 2 files changed, 24 insertions(+) diff --git a/features/shell.feature b/features/shell.feature index d5595506..bcaeaa18 100644 --- a/features/shell.feature +++ b/features/shell.feature @@ -61,6 +61,28 @@ Feature: WordPress REPL """ And STDERR should be empty + Scenario: Use SHELL environment variable as fallback + Given a WP install + + And a session file: + """ + return true; + """ + + When I try `SHELL=/bin/bash wp shell --basic < session` + Then STDOUT should contain: + """ + bool(true) + """ + And STDERR should be empty + + When I try `SHELL=/nonsense/path wp shell --basic < session` + Then STDOUT should be empty + And STDERR should contain: + """ + Error: The shell binary '/nonsense/path' is not valid. + """ + Scenario: Input starting with dash Given a WP install And a session file: diff --git a/src/WP_CLI/Shell/REPL.php b/src/WP_CLI/Shell/REPL.php index 99b8f1f8..d39bee91 100644 --- a/src/WP_CLI/Shell/REPL.php +++ b/src/WP_CLI/Shell/REPL.php @@ -122,6 +122,8 @@ private static function create_prompt_cmd( $prompt, $history_path ) { $history_path = escapeshellarg( $history_path ); if ( getenv( 'WP_CLI_CUSTOM_SHELL' ) ) { $shell_binary = getenv( 'WP_CLI_CUSTOM_SHELL' ); + } elseif ( getenv( 'SHELL' ) ) { + $shell_binary = getenv( 'SHELL' ); } else { $shell_binary = '/bin/bash'; } From 325dbde8c93194c6fa6034ba9e2aec4b984f8a8d Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 2 Feb 2026 20:46:00 -0500 Subject: [PATCH 3/5] Update features/shell.feature Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- features/shell.feature | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/features/shell.feature b/features/shell.feature index bcaeaa18..2974601f 100644 --- a/features/shell.feature +++ b/features/shell.feature @@ -77,11 +77,11 @@ Feature: WordPress REPL And STDERR should be empty When I try `SHELL=/nonsense/path wp shell --basic < session` - Then STDOUT should be empty - And STDERR should contain: + Then STDOUT should contain: """ - Error: The shell binary '/nonsense/path' is not valid. + bool(true) """ + And STDERR should be empty Scenario: Input starting with dash Given a WP install From d424ea89a410f5063c9ab82a11eda60958fb5fd2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 02:01:33 +0000 Subject: [PATCH 4/5] Prefer /bin/bash and only use SHELL for bash shells Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/shell.feature | 12 +++++++++++- src/WP_CLI/Shell/REPL.php | 23 +++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/features/shell.feature b/features/shell.feature index 2974601f..c5e39699 100644 --- a/features/shell.feature +++ b/features/shell.feature @@ -61,7 +61,7 @@ Feature: WordPress REPL """ And STDERR should be empty - Scenario: Use SHELL environment variable as fallback + Scenario: Use SHELL environment variable as fallback for bash Given a WP install And a session file: @@ -69,6 +69,7 @@ Feature: WordPress REPL return true; """ + # SHELL pointing to bash should work (when bash is available). When I try `SHELL=/bin/bash wp shell --basic < session` Then STDOUT should contain: """ @@ -76,6 +77,15 @@ Feature: WordPress REPL """ And STDERR should be empty + # SHELL pointing to non-bash shell should be ignored and fall back to /bin/bash. + When I try `SHELL=/bin/zsh wp shell --basic < session` + Then STDOUT should contain: + """ + bool(true) + """ + And STDERR should be empty + + # SHELL pointing to invalid path should be ignored and fall back to /bin/bash. When I try `SHELL=/nonsense/path wp shell --basic < session` Then STDOUT should contain: """ diff --git a/src/WP_CLI/Shell/REPL.php b/src/WP_CLI/Shell/REPL.php index d39bee91..670e6ce7 100644 --- a/src/WP_CLI/Shell/REPL.php +++ b/src/WP_CLI/Shell/REPL.php @@ -122,10 +122,15 @@ private static function create_prompt_cmd( $prompt, $history_path ) { $history_path = escapeshellarg( $history_path ); if ( getenv( 'WP_CLI_CUSTOM_SHELL' ) ) { $shell_binary = getenv( 'WP_CLI_CUSTOM_SHELL' ); - } elseif ( getenv( 'SHELL' ) ) { + } elseif ( is_file( '/bin/bash' ) && is_readable( '/bin/bash' ) ) { + // Prefer /bin/bash when available since we use bash-specific commands. + $shell_binary = '/bin/bash'; + } elseif ( getenv( 'SHELL' ) && self::is_bash_shell( getenv( 'SHELL' ) ) ) { + // Only use SHELL as fallback if it's bash (we use bash-specific commands). $shell_binary = getenv( 'SHELL' ); } else { - $shell_binary = '/bin/bash'; + // Final fallback for systems without /bin/bash. + $shell_binary = 'bash'; } if ( ! is_file( $shell_binary ) || ! is_readable( $shell_binary ) ) { @@ -146,6 +151,20 @@ private static function create_prompt_cmd( $prompt, $history_path ) { return "{$shell_binary} -c " . escapeshellarg( $cmd ); } + /** + * Check if a shell binary is bash or bash-compatible. + * + * @param string $shell_path Path to the shell binary. + * @return bool True if the shell is bash, false otherwise. + */ + private static function is_bash_shell( $shell_path ) { + if ( ! is_file( $shell_path ) || ! is_readable( $shell_path ) ) { + return false; + } + // Check if the basename contains 'bash'. + return false !== strpos( basename( $shell_path ), 'bash' ); + } + private function set_history_file() { $data = getcwd() . get_current_user(); From 8eae8ef998fed23a7a0c49b659c842185fd8d961 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 02:02:49 +0000 Subject: [PATCH 5/5] Improve bash detection and test reliability Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/shell.feature | 4 ++-- src/WP_CLI/Shell/REPL.php | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/features/shell.feature b/features/shell.feature index c5e39699..26f05137 100644 --- a/features/shell.feature +++ b/features/shell.feature @@ -77,8 +77,8 @@ Feature: WordPress REPL """ And STDERR should be empty - # SHELL pointing to non-bash shell should be ignored and fall back to /bin/bash. - When I try `SHELL=/bin/zsh wp shell --basic < session` + # SHELL pointing to non-bash binary should be ignored and fall back to /bin/bash. + When I try `SHELL=/bin/sh wp shell --basic < session` Then STDOUT should contain: """ bool(true) diff --git a/src/WP_CLI/Shell/REPL.php b/src/WP_CLI/Shell/REPL.php index 670e6ce7..52af4139 100644 --- a/src/WP_CLI/Shell/REPL.php +++ b/src/WP_CLI/Shell/REPL.php @@ -161,8 +161,9 @@ private static function is_bash_shell( $shell_path ) { if ( ! is_file( $shell_path ) || ! is_readable( $shell_path ) ) { return false; } - // Check if the basename contains 'bash'. - return false !== strpos( basename( $shell_path ), 'bash' ); + // Check if the basename is exactly 'bash' or starts with 'bash' followed by a version/variant. + $basename = basename( $shell_path ); + return 'bash' === $basename || 0 === strpos( $basename, 'bash-' ); } private function set_history_file() {