I am seeing the following error from Tramp:
tramp-error: ‘echo \"`uname -sr`\"’ does not return a valid Lisp expression: ‘"MSYS_NT-10.0-22631 3.4.10-87d57229.x86_64" [17;120H’

Background:

I have a "Windows 11 Home Edition" remote machine, and am seeking to connect to that machine from emacs run on macOS.

In emacs, I am doing:
(find-file "/ssh:WINUSERNAME@WIN11HOME:WINPATH")
with suitable values for WINUSERNAME, WIN11HOME, WINPATH.

I can ssh to WIN11HOME (it is running the OpenSSH Server), using keys stored locally in my macOS.

By default, the shell produced for the ssh to windows is a PowerShell, which I can well understand is not what Tramp expects; Tramp was producing an error "Couldn't find remote shell prompt for /bin/sh". 

To address, now I detect the tramp attach on the Windows side and, in the Tramp case, move to shell "sh" for the Windows prompt.

Thereafter, tramp produces the "uname/lisp" error above.

FYI, from the windows side:
    sh-5.2$ uname -sr
    MSYS_NT-10.0-22631 3.4.10-87d57229.x86_64

Thanks in advance.
------

In GNU Emacs 29.1 (build 1, aarch64-apple-darwin21.6.0, NS
 appkit-2113.60 Version 12.6.6 (Build 21G646)) of 2023-08-16 built on
 armbob.lan
Windowing system distributor 'Apple', version 10.3.2487
System Description:  macOS 14.5

Configured using:
 'configure --with-ns '--enable-locallisppath=/Library/Application
 Support/Emacs/${version}/site-lisp:/Library/Application
 Support/Emacs/site-lisp' --with-modules 'CFLAGS=-DFD_SETSIZE=10000
 -DDARWIN_UNLIMITED_SELECT' --with-x-toolkit=no'

Configured features:
ACL GLIB GMP GNUTLS JPEG JSON LIBXML2 MODULES NOTIFY KQUEUE NS PDUMPER
PNG RSVG SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Text

Minor modes in effect:
  shell-dirtrack-mode: t
  auto-revert-mode: t
  server-mode: t
  override-global-mode: t
  delete-selection-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  column-number-mode: t
  line-number-mode: t
  auto-fill-function: do-auto-fill
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
/Users/USERNAME/.emacs.d/lisp/dash hides /Users/USERNAME/.emacs.d/elpa/dash-20221013.836/dash
/Users/USERNAME/.emacs.d/elpa/use-package-20221029.1857/use-package-jump hides /Applications/Emacs.app/Contents/Resources/lisp/use-package/use-package-jump
/Users/USERNAME/.emacs.d/elpa/use-package-20221029.1857/use-package-ensure hides /Applications/Emacs.app/Contents/Resources/lisp/use-package/use-package-ensure
/Users/USERNAME/.emacs.d/elpa/use-package-20221029.1857/use-package-core hides /Applications/Emacs.app/Contents/Resources/lisp/use-package/use-package-core
/Users/USERNAME/.emacs.d/elpa/use-package-20221029.1857/use-package-delight hides /Applications/Emacs.app/Contents/Resources/lisp/use-package/use-package-delight
/Users/USERNAME/.emacs.d/elpa/use-package-20221029.1857/use-package-diminish hides /Applications/Emacs.app/Contents/Resources/lisp/use-package/use-package-diminish
/Users/USERNAME/.emacs.d/elpa/use-package-20221029.1857/use-package hides /Applications/Emacs.app/Contents/Resources/lisp/use-package/use-package
/Users/USERNAME/.emacs.d/elpa/use-package-20221029.1857/use-package-bind-key hides /Applications/Emacs.app/Contents/Resources/lisp/use-package/use-package-bind-key
/Users/USERNAME/.emacs.d/elpa/bind-key-20221028.1858/bind-key hides /Applications/Emacs.app/Contents/Resources/lisp/use-package/bind-key
/Users/USERNAME/.emacs.d/elpa/use-package-20221029.1857/use-package-lint hides /Applications/Emacs.app/Contents/Resources/lisp/use-package/use-package-lint
/Users/USERNAME/.emacs.d/lisp/linum hides /Applications/Emacs.app/Contents/Resources/lisp/obsolete/linum

Features:
(shadow mail-extr emacsbug dired-aux vc-hg vc-git diff-mode vc-bzr
vc-dispatcher misearch multi-isearch display-line-numbers
company-oddmuse company-keywords company-etags company-gtags
company-dabbrev-code company-dabbrev company-files company-clang
company-capf company-cmake company-semantic company-template
company-bbdb company tramp-cmds tramp-cache time-stamp tramp-sh tramp
tramp-loaddefs trampver tramp-integration files-x tramp-compat shell
parse-time iso8601 mm-archive message sendmail yank-media dired
dired-loaddefs rfc822 mml mml-sec epa derived epg rfc6068 gnus-util
mailabbrev gmm-utils mailheader mm-decode mm-bodies mm-encode mail-utils
sort autorevert filenotify tango-theme server cmake-mode rst
persistent-todo todotxt rustic-spellcheck rustic-expand rustic-lsp
rustic-playpen rustic-rustfix rustic-racer etags fileloop xref
rustic-babel rustic-rustfmt project org-element org-persist org-id
org-refile avl-tree generator org ob ob-tangle ob-ref ob-lob ob-table
ob-exp org-macro org-src ob-comint org-pcomplete pcomplete org-list
org-footnote org-faces org-entities time-date ob-emacs-lisp ob-core
ob-eval org-cycle org-table ol org-fold org-fold-core org-keys oc
org-loaddefs find-func cal-menu calendar cal-loaddefs org-version
org-compat org-macs format-spec rustic-comint rustic-clippy rustic-doc
xdg f f-shortdoc shortdoc rustic-popup rustic-cargo rustic-compile
spinner s xterm-color markdown-mode color noutline outline icons
rustic-interaction rustic dash pcase use-package use-package-ensure
use-package-delight use-package-diminish use-package-bind-key bind-key
easy-mmode use-package-core rust-utils thingatpt rust-mode rx
rust-rustfmt rust-playpen rust-compile compile text-property-search
comint ansi-osc ansi-color ring rust-cargo gnutls network-stream
url-cache url-http url-auth mail-parse rfc2231 rfc2047 rfc2045 mm-util
ietf-drums mail-prsvr url-gw nsm puny epg-config finder-inf
special-scratch kmacro advice string-inflection cl-extra help-mode
desktop frameset unbound cl delsel auto-complete-autoloads
cmake-font-lock-autoloads cmake-mode-autoloads company-autoloads
fuzzy-autoloads popup-complete-autoloads popup-autoloads info package
browse-url url url-proxy url-privacy url-expand url-methods url-history
url-cookie generate-lisp-file url-domsuf url-util mailcap url-handlers
url-parse auth-source cl-seq eieio eieio-core cl-macs password-cache
json subr-x map byte-opt gv bytecomp byte-compile url-vars cl-loaddefs
cl-lib rmc iso-transl tooltip cconv eldoc paren electric uniquify
ediff-hook vc-hooks lisp-float-type elisp-mode mwheel term/ns-win ns-win
ucs-normalize mule-util term/common-win tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu
timer select scroll-bar mouse jit-lock font-lock syntax font-core
term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads kqueue cocoa ns multi-tty
make-network-process emacs)

Memory information:
((conses 16 415911 148371)
 (symbols 48 28452 0)
 (strings 32 147379 43984)
 (string-bytes 1 3839566)
 (vectors 16 54725)
 (vector-slots 8 1462349 223260)
 (floats 8 315 537)
 (intervals 56 738 0)
 (buffers 984 16))