1

How to do command substitution à la Bash in Eshell, and not just for loops? (Unfortunately, while this question asks my question, its answer only provides Eshell for-loop syntax. So please don't dupe me with that: I seek an answer to the general question, using the example below.) FWIW,

  • I'm a longtime Basher trying to learn Eshell. I like to think I'm Bash-strong (at least, I've been using it forever both at commandline and for scripts) but ...
  • ... I know I'm Elisp-weak. I've adapted or written a few functions for my init.el and do some C-u M-: in buffers, but that's about it.
  • I'm running Emacs on a Linux.

For this usecase, I want to look at all the *Office docs in a particular filetree

  1. sorted by time (required)
  2. in a Dired buffer (preferred)

Let the filetree root=~/foo/bar/. I can satisfy condition 2 with find-name-dired, but not condition 1: when I do

M-x find-name-dired ~/foo/bar/ *.odt

and then press s in the resulting buffer, I get the error

Cannot sort this Dired buffer

So I think, "I know how to do this in Bash. Perhaps if I do it in Eshell, that will give me a Dired buffer?" So I do

M-x eshell

but get

Welcome to the Emacs shell

~/foo/bar $ ls -alt $(find . -name '*.odt')
Invalid read syntax: ". in wrong context"

I assume that's a Lispism, and instead try

~/foo/bar $ ls -alt $(find ./ -name '*.odt')
Invalid read syntax: ")"

I've tried escaping the {parentheses, round brackets} various ways, and even backticks (note to reader--don't use backticks :-) to no avail: I either get the Invalid read syntax: ")" or more catastrophic errors. I then tried various sorts of C-h and websearch, without success. What am I doing wrong, and how to fix?

TomRoche
  • 592
  • 3
  • 20

1 Answers1

5

I then tried various sorts of C-h and websearch, without success.

Please check the manual first! (or second, after docstrings) (eshell) Dollars Expansion:

Eshell has different ‘$’ expansion syntax from other shells.  There are
some similarities, but don’t let these lull you into a false sense of
familiarity.
[...]
‘${command}’
     Returns the output of ‘command’, which can be any valid Eshell
     command invocation, and may even contain expansions.

So ls -alt ${find . -name '*.odt'} should work. However,

So I think, "I know how to do this in Bash. Perhaps if I do it in Eshell, that will give me a Dired buffer?"

It will not.

npostavs
  • 9,033
  • 1
  • 21
  • 53