GNU bug report logs - #27361
24.4; eshell/echo silently ignores -n argument

Previous Next

Package: emacs;

Reported by: Phil Hagelberg <phil <at> hagelb.org>

Date: Wed, 14 Jun 2017 16:17:02 UTC

Severity: wishlist

Found in version 24.4

Fixed in version 29.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


Message #25 received at 27361 <at> debbugs.gnu.org (full text, mbox):

From: Jim Porter <jporterbugs <at> gmail.com>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Glenn Morris <rgm <at> gnu.org>, 27361 <at> debbugs.gnu.org
Subject: Re: Re: bug#27361: 24.4; eshell/echo silently ignores -n argument
Date: Sat, 15 Jan 2022 23:19:50 -0800
[Message part 1 (text/plain, inline)]
On 9/15/2020 8:27 AM, Lars Ingebrigtsen wrote:
> Glenn Morris <rgm <at> gnu.org> writes:
> 
>> -      (concat (apply 'eshell-flatten-and-stringify args) "\n")
>> +      (concat (apply 'eshell-flatten-and-stringify args)
>> +	      (unless output-newline "\n"))
> 
> Hm...  with or without the patch, and with eshell-plain-echo-behavior
> set, I don't see any difference?
> 
> I still get this in eshell:
> 
> ~/src/emacs/trunk $ echo -n foo; echo bar
> foo
> bar

I think this is due to `eshell-lisp-command' insisting that a newline is 
inserted after the output of *every* Lisp command (when executed 
interactively). It's easier to see what "-n" does by eval'ing:

  (eshell-command-result "echo hi")
  ;; and
  (eshell-command-result "echo -n hi")

One solution to this bug would be to set `eshell-ensure-newline-p' to 
nil inside `eshell-echo'; then it will opt out of `eshell-lisp-command's 
trailing-newline insertion.

I've attached a patch that does this, as well as (hopefully) resolving 
the unusual meaning of "-n" when echo outputs a Lisp-friendly result 
(i.e. when `eshell-plain-echo-behavior' is nil). Now, it warns the user 
to use "-N" instead if they want to add a trailing newline. Then, one 
day, the old meaning of "-n" can be removed. I'm not sure if this is the 
best way to emit a warning about this though; I wanted something that 
doesn't interfere with any Eshell scripts, but `display-warning' is a 
bit in-your-face.

I also simplified the logic of `eshell/printnl'. Since the way it called 
`eshell-echo' always resulted in it printing the stringified form of 
each argument, it's simpler just to call `eshell-stringify' directly.

Finally, I added a bit more detail about echo to the Eshell manual 
(taken partly from the commentary of eshell/em-basic.el), since I didn't 
quite understand its behavior initially.
[0001-In-Eshell-allow-n-to-suppress-the-trailing-newline-f.patch (text/plain, attachment)]

This bug report was last modified 3 years and 123 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.