bitcoinNeverSleeps
bitcoinNeverSleeps

Reputation: 197

Make Emacs eshell / echo newlines behave like in a regular terminal

I noticed that when you ask, say, echo to not output the trailing newline in an Emacs eshell, it still does add it.

For example, from Bash:

$ echo -n "a" | sha1sum 
86f7e437faa5a7fce15d1ddcb9eaeaea377667b8  -

From Emacs' eshell:

$ echo -n "a" | sha1sum 
3f786850e387550fdab836ed7e6dc881de23001b  -

The reason is that an additional byte is added:

From Bash:

$ echo -n "a" | wc -c
1

From eshell:

$ echo -n "a" | wc -c
2

And using hexdump, here's the output:

$ echo -n "a" | hexdump -C
00000000  61 0a                                             |a.|

I'm a bit puzzled by that finding: there's an 0a (ASCII control code for "new line") added which shouldn't be there (the "-n" option passed to echo is supposed to not add the newline).

What kind of elisp configuration magic is needed so that Emacs' eshell doesn't add a newline before piping the output of echo to other commands?

P.S: Emacs 24.3.50.1 on Debian Linux.

Upvotes: 3

Views: 386

Answers (1)

phils
phils

Reputation: 73274

eshell-echo appears to invert the typical (sh/bash) meaning of -n, which is probably unfortunate. (FYI it does tell you this if you type echo -h.)

In addition, if eshell-plain-echo-behavior is non-nil it forces a newline onto the end of the arguments.

So you want that variable nil, and you want to use echo with no -n argument.

Upvotes: 2

Related Questions