ErgoEmacsEmacsLispBlogEmacsLispBuy Tutorial

Emacs: What's eshell? “eshell” vs “shell” Difference?

, ,

I've always thought that eshell was just a toy, and never really tried to use it other than knowning it's written entirely in elisp. But over the past few years i learned from emacs community, that apparently many people do use it. Also, because eshell is written in emacs lisp, that means you can enter elisp code or call any of the 3000+ elisp commands or functions directly in the eshell command line.

For example, try typing (+ 3 4) in the prompt, and it returns “7”.

What's eshell? how's it different from shell?

eshell is written entirely in elisp.

Practically speaking, that means when you are on Windows and don't have Cygwin installed, you can still use all the common unix commands {ls, cd, mkdir, cp, grep, …}, in eshell.

How to set environment variable FOR eshell?

you can get and set environment variables for emacs use only by:

; show env var named path
(getenv "PATH")

; example of setting env var named “path”
; by prepending new paths to existing paths
(setenv "PATH"
  (concat
   "C:/cygwin/usr/local/bin" ";"
   "C:/cygwin/usr/bin" ";"
   "C:/cygwin/bin" ";"
   (getenv "PATH") ; inherited from OS
  )
)

Put in your emacs init file. Restart emacs, or, select the code then call eval-region.

This will effect environment variable within emacs only. It won't change the real environment variables used by OS.

When you call a command such as “perl” that's not in eshell, eshell will try to find it in the env var PATH. Also, emacs do inherit your PATH environment variable from OS. For detail, see: Emacs and Microsoft Windows Tips.

Advantages of Eshell Over a Regular Shell

NikkiA at reddit gave some very useful tips:

Here's a more in-depth tutorial about eshell. Mastering Eshell by Mickey @ www.masteringemacs.org…

Eshell is written by John Wiegley. Thank you John.

eshell Tricks

output shell command to buffer

ls > #<buffer ttt>

output shell command to a buffer.

once you did that, you can switch to buffer easily especially if you use iswitchb-buffer. (you should, if not already. Just call iswitchb-mode to turn it on. Then the key 【Ctrl+x b】 does the switch.)

though, this to me seems still too much to type #<buffer ttt>. If the output is not pages long, easier to simply copy & paste.

thanks to Gregory Collins.

eshell Pains

eshell is great. But because it's a complete new shell, it has learning pains, as well as some quirks. Here's some collection of problems, some are due to me not understanding eshell.

eshell doesn't have any documentation.

in shell, i can run this to convert all gif to png:

find . -name "*gif" | xargs -l -i basename "{}" ".gif" | xargs -l -i  convert "{}.gif" "{}.png"

but in eshell, i get this error:

convert: unable to open image `.gif': No such file or directory.
convert: missing an image filename `.png'.
convert: unable to open image `.gif': No such file or directory.
convert: missing an image filename `.png'.

Spawning child process: invalid argument

why doesn't this work in eshell?

lynx -dump -display_charset=utf-8 -width=90 http://xahlee.org/ > x.html

i get:

Spawning child process: invalid argument

Solution: on Windows, it needs to be lynx.exe. Else, eshell gets confused.

Source groups.google.com

find problem?

in emacs eshell, why the following doesn't work?

find . -name "*bmp"
~/web/xahlee_org/math/i/bejeweled $ find . -name "*bmp" 
/usr/bin/find: paths must precede expression: x183313.bmp
Usage: /usr/bin/find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression] 

Source plus.google.com

Andrew Hyatt: Try echoing to make sure that eshell is doing what you think. Or `set-trace' the call-process call to see what exactly is getting run.

, it works now. No idea why.

blog comments powered by Disqus