Subject: bug#73479: 30.0.91; eshell: error on some env calls

From: Jim Porter <[email-masked]>
Date: Wed, 25 Sep 2024 12:08:07 -0700

On 9/25/2024 10:01 AM, Christopher Howard wrote:
> 
> 1. emacs -Q
> 2. M-x eshell
> 3. env ls <ENTER>
>     or
>     env eshell <ENTER>
> 
> Note that if you are set up to use the system "env" instead, this problem won't show up. Also, it works correctly with "env FOO=bar ls", "env cd", and other combinations that I tested.

Thanks for noticing this. Here's a patch. Eli, is this ok for Emacs 30? 
It's a bug in a newly-added feature, and the fix is simple (plus it has 
a regression test).

From 576e79474e874414a58264212716fff379e2b70a Mon Sep 17 00:00:00 2001
From: Jim Porter <[email-masked]>
Date: Wed, 25 Sep 2024 11:59:32 -0700
Subject: [PATCH] Fix executing commands in Eshell using "env" with no local
 variables

* lisp/eshell/esh-var.el (eshell/env): Throw 'eshell-replace-command' as
needed.

* test/lisp/eshell/esh-var-tests.el
(esh-var-test/local-variables/env/no-locals): New test (bug#73479).
---
 lisp/eshell/esh-var.el            | 3 ++-
 test/lisp/eshell/esh-var-tests.el | 5 +++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/lisp/eshell/esh-var.el b/lisp/eshell/esh-var.el
index f0270aca92c..1b54f1862be 100644
--- a/lisp/eshell/esh-var.el
+++ b/lisp/eshell/esh-var.el
@@ -436,7 +436,8 @@ eshell/env
      :usage "[NAME=VALUE]... [COMMAND]...")
    (if args
        (or (eshell-parse-local-variables args)
-           (eshell-named-command (car args) (cdr args)))
+           (throw 'eshell-replace-command
+                  `(eshell-named-command ,(car args) ',(cdr args))))
      (eshell-with-buffered-print
        (dolist (setting (sort (eshell-environment-variables) 'string-lessp))
          (eshell-buffered-print setting "\n"))))))
diff --git a/test/lisp/eshell/esh-var-tests.el b/test/lisp/eshell/esh-var-tests.el
index 6b0e225f05f..7b29e4a21db 100644
--- a/test/lisp/eshell/esh-var-tests.el
+++ b/test/lisp/eshell/esh-var-tests.el
@@ -669,6 +669,11 @@ esh-var-test/local-variables/env
    (eshell-match-command-output "env VAR=hello env" "VAR=hello\n")
    (should (equal (getenv "VAR") "value"))))
 
+(ert-deftest esh-var-test/local-variables/env/no-locals ()
+  "Test that \"env command\" works like \"command\"."
+  (with-temp-eshell
+   (eshell-match-command-output "env echo hi" "\\`hi\n")))
+
 
 ;; Variable aliases
 
-- 
2.25.1