Skip to content

Commit 8eae8ef

Browse files
Copilotswissspidy
andcommitted
Improve bash detection and test reliability
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent d424ea8 commit 8eae8ef

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

features/shell.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ Feature: WordPress REPL
7777
"""
7878
And STDERR should be empty
7979
80-
# SHELL pointing to non-bash shell should be ignored and fall back to /bin/bash.
81-
When I try `SHELL=/bin/zsh wp shell --basic < session`
80+
# SHELL pointing to non-bash binary should be ignored and fall back to /bin/bash.
81+
When I try `SHELL=/bin/sh wp shell --basic < session`
8282
Then STDOUT should contain:
8383
"""
8484
bool(true)

src/WP_CLI/Shell/REPL.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,9 @@ private static function is_bash_shell( $shell_path ) {
161161
if ( ! is_file( $shell_path ) || ! is_readable( $shell_path ) ) {
162162
return false;
163163
}
164-
// Check if the basename contains 'bash'.
165-
return false !== strpos( basename( $shell_path ), 'bash' );
164+
// Check if the basename is exactly 'bash' or starts with 'bash' followed by a version/variant.
165+
$basename = basename( $shell_path );
166+
return 'bash' === $basename || 0 === strpos( $basename, 'bash-' );
166167
}
167168

168169
private function set_history_file() {

0 commit comments

Comments
 (0)