From 86703b8308bc2cd9336c03c71649d2b79ef3354f Mon Sep 17 00:00:00 2001 From: Jim Porter 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). (cherry picked from commit 11e3e0cadd46ee49007477af1335ddd5365debe2) --- 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 0e6c01d2774..5d7ea1c3664 100644 --- a/lisp/eshell/esh-var.el +++ b/lisp/eshell/esh-var.el @@ -436,7 +436,8 @@ the values of nil for each." :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 @@ nil, use FUNCTION instead." (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.39.2