[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#59666: 29.0.50; Eshell: comparisons such as {> 3 2} do not work in E
From: |
Jim Porter |
Subject: |
bug#59666: 29.0.50; Eshell: comparisons such as {> 3 2} do not work in Eshell context |
Date: |
Mon, 28 Nov 2022 18:03:41 -0800 |
On 11/28/2022 4:15 PM, Milan Zimmermann wrote:
All behavior of comparisons below is incorrect
# Comparisons using ">"
This is actually working as intended, though it's another one of those
surprising behaviors that you tend to get in Eshell due to its fusion of
Lisp and shell syntax.
The problem is that ">" and "<" are I/O redirection operators (though
"<" isn't actually implemented yet). If you want to do a less- or
greater-than comparison using command-style syntax, you'd need to escape it:
~ $ \> 3 2
t
### 4.
~/tmp $ if {> 3 2} {echo YES} {echo NO}
Actual: NO
Expected: YES
One additional note. Even with the proper escapes, that won't work right:
~ $ if {\> 3 2} {echo YES} {echo NO}
YES
~ $ if {\> 3 4} {echo YES} {echo NO}
YES ;; Wrong!
That's because the above form is actually just checking, "Did the Lisp
function '>' signal an error?"[1] You'd need to use ${} expansion, which
expands to the *output* of the subcommand (and then checks that it's
non-nil), or the Lisp form $()/():
~ $ if ${\> 3 2} {echo YES} {echo NO}
YES
~ $ if ${\> 3 4} {echo YES} {echo NO}
NO
~ $ if (> 3 2) {echo YES} {echo NO}
YES
~ $ if (> 3 4) {echo YES} {echo NO}
NO
~ $ if $(> 3 2) {echo YES} {echo NO}
YES
~ $ if $(> 3 4) {echo YES} {echo NO}
NO
Maybe {...} forms should work more like (...) forms when it finds a Lisp
function that's not prefixed with 'eshell/'. I'll have to think about
this some more though...
[1] This is all assuming there's no external program named ">".