unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#55236: 29.0.50; Surprising behaviors with Eshell expansions
@ 2022-05-03  3:41 Jim Porter
  2022-05-03  3:45 ` bug#55236: [PATCH] " Jim Porter
  2022-05-03  9:32 ` Michael Albinus
  0 siblings, 2 replies; 5+ messages in thread
From: Jim Porter @ 2022-05-03  3:41 UTC (permalink / raw)
  To: 55236

(Note: this is closely related to bug#12689, but this isn't *quite* a 
fix for that bug. This bug is also somewhat broader in scope, so it felt 
like a new bug was the best place for it. I'll comment on that bug 
shortly with further details.)

There are several inconsistencies with how Eshell expansions are, well, 
expanded. These are arguably separate bugs, but they're closely-enough 
related that I think it's best to discuss them all at once so that 
everyone can see the full context (especially since any changes here 
could conceivably cause incompatibilities).

1. Quoted Expansions
--------------------

 From "emacs -Q --eval '(eshell)'":

   ~ $ type-of 1
   integer
   ~ $ type-of "1"
   string
   ~ $ setq foo 1
   1
   ~ $ type-of $foo
   integer
   ~ $ type-of "$foo"
   integer

Surprisingly, the last line shows that "$foo" is an integer, even though 
double-quotes are used in Eshell to disable conversion to numbers. For 
another example, first try this in your favorite shell (tested in dash, 
bash, and zsh):

   $ cat args
   #!/usr/bin/env python3

   import sys
   print(sys.argv[1:])

   $ ./args $(/bin/echo -e "foo\nbar")
   ['foo', 'bar']
   $ ./args "$(/bin/echo -e "foo\nbar")"
   ['foo\nbar']

Now in "emacs -Q --eval '(eshell)'":

   ~ $ ./args ${/bin/echo -e "foo\nbar"}
   ['foo', 'bar']
   ~ $ ./args "${/bin/echo -e \"foo\nbar\"}"
   ['foo', 'bar']

Again, wrapping the Eshell expansion in double-quotes doesn't do 
anything. It should probably work like other shells.

2. Converting subcommand output to numbers
------------------------------------------

 From "emacs -Q --eval '(eshell)'":

   ~ $ type-of ${/bin/echo "1"}
   integer
   ~ $ echo ${/bin/echo -e "1\n2"}
   ("1" "2")
   ~ $ type-of ${/bin/echo -e "1\n2"}[0]
   string

Eshell converts ${SUBCOMMAND} output to a number, but only if there's a 
*single* number. If there are multiple lines with numbers, you just get 
a list of strings. This is somewhat inconvenient, since you might want 
to add the numbers up, e.g. by typing:

   ~ $ apply #'+ ${/bin/echo -e "1\n2"}
   Wrong type argument: number-or-marker-p, "1"

(This might seem unrelated, but it ties directly into the next issue.)

3. Concatenating expansions
---------------------------

Like in other shells, you can concatenate expansions with strings or 
other expansions. From "emacs -Q --eval '(eshell)'":

   ~ $ echo ${*echo "1"}2
   12
   ~ $ type-of ${*echo "1"}2
   integer

That's fine (at least once you know to expect it), but there are some 
odd corner cases:

   ~ $ setq foo "1"
   1
   ~ $ type-of $foo
   string
   ~ $ type-of $'foo'2
   integer

Here, concatenating two strings produces an integer, since the string 
"12" looks numeric. I think that's an overly-aggressive conversion. 
Similarly, when the expansion returns a list, the result is surprising 
(this is one of the things bug#12689 is about):

   ~ $ ./args ${/bin/echo -e "foo\nbar"}-baz
   ['("foo" "bar")-baz']

This time, the result is the list of lines from /bin/echo, converted to 
a string, and then concatenated with "-baz" into a single string. That's 
surprising, since doing the same sort of thing in dash/bash/zsh produces 
the following:

   $ ./args $(/bin/echo -e "foo\nbar")-baz
   ['foo', 'bar-baz']

I'll post patches for these shortly (just getting a bug number).





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-05-03 16:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-03  3:41 bug#55236: 29.0.50; Surprising behaviors with Eshell expansions Jim Porter
2022-05-03  3:45 ` bug#55236: [PATCH] " Jim Porter
2022-05-03  4:20   ` bug#55236: [PATCH v2] " Jim Porter
2022-05-03 16:24     ` bug#55236: " Lars Ingebrigtsen
2022-05-03  9:32 ` Michael Albinus

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).