bug#27361: 24.4; eshell/echo silently ignores -n argument

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

bug#27361: 24.4; eshell/echo silently ignores -n argument

Phil Hagelberg-2

When using eshell, the `echo' built-in doesn't respect the -n argument,
which is supposed to suppress the trailing newline.

Sometimes this is not a problem because you can see for yourself that
eshell did the wrong thing, but if you are piping it directly to another
command, it's easy to miss.

The eshell/echo function should be changed to either accept the -n
argument and omit the newline, or it should complain that -n is not a
supported argument.



In GNU Emacs 24.4.1 (x86_64-pc-linux-gnu, GTK+ Version 3.14.5)
 of 2015-03-07 on trouble, modified by Debian
Windowing system distributor `The X.Org Foundation', version 11.0.11604000
System Description: Debian GNU/Linux 8.8 (jessie)

Configured using:
 `configure --build x86_64-linux-gnu --prefix=/usr
 --sharedstatedir=/var/lib --libexecdir=/usr/lib
 --localstatedir=/var/lib --infodir=/usr/share/info
 --mandir=/usr/share/man --with-pop=yes
 --enable-locallisppath=/etc/emacs24:/etc/emacs:/usr/local/share/emacs/24.4/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.4/site-lisp:/usr/share/emacs/site-lisp
 --build x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib
 --libexecdir=/usr/lib --localstatedir=/var/lib
 --infodir=/usr/share/info --mandir=/usr/share/man --with-pop=yes
 --enable-locallisppath=/etc/emacs24:/etc/emacs:/usr/local/share/emacs/24.4/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.4/site-lisp:/usr/share/emacs/site-lisp
 --with-x=yes --with-x-toolkit=gtk3 --with-toolkit-scroll-bars
 'CFLAGS=-g -O2 -fstack-protector-strong -Wformat
 -Werror=format-security -Wall' CPPFLAGS=-D_FORTIFY_SOURCE=2
 LDFLAGS=-Wl,-z,relro'

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: EShell

Minor modes in effect:
  ido-ubiquitous-mode: t
  winner-mode: t
  diff-auto-refine-mode: t
  show-paren-mode: t
  tooltip-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
e c h o SPC - n SPC w a <backspace> <backspace> c o
m e SPC o n SPC n o w <return> M-p SPC | S-SPC c a
t <return> M-x r e p o r t - e m <return>

Recent messages:
Loading em-dirs...done
Loading em-glob...done
Loading em-hist...done
Loading em-ls...done
Loading em-prompt...done
Loading em-script...done
Loading em-term...done
Loading em-unix...done
For information about GNU Emacs and the GNU system, type C-h C-a.
History item: 128

Load-path shadows:
~/.emacs.d/lib/yaml-mode/yaml-mode hides /usr/share/emacs24/site-lisp/yaml-mode/yaml-mode
/usr/share/emacs/site-lisp/mu4e/mu4e-speedbar hides /usr/share/emacs24/site-lisp/mu4e/mu4e-speedbar
/usr/share/emacs/site-lisp/mu4e/mu4e-message hides /usr/share/emacs24/site-lisp/mu4e/mu4e-message
/usr/share/emacs/site-lisp/mu4e/mu4e hides /usr/share/emacs24/site-lisp/mu4e/mu4e
/usr/share/emacs/site-lisp/mu4e/mu4e-about hides /usr/share/emacs24/site-lisp/mu4e/mu4e-about
/usr/share/emacs/site-lisp/mu4e/mu4e-contrib hides /usr/share/emacs24/site-lisp/mu4e/mu4e-contrib
/usr/share/emacs/site-lisp/mu4e/mu4e-mark hides /usr/share/emacs24/site-lisp/mu4e/mu4e-mark
/usr/share/emacs/site-lisp/mu4e/mu4e-vars hides /usr/share/emacs24/site-lisp/mu4e/mu4e-vars
/usr/share/emacs/site-lisp/mu4e/mu4e-headers hides /usr/share/emacs24/site-lisp/mu4e/mu4e-headers
/usr/share/emacs/site-lisp/mu4e/mu4e-proc hides /usr/share/emacs24/site-lisp/mu4e/mu4e-proc
/usr/share/emacs/site-lisp/mu4e/mu4e-main hides /usr/share/emacs24/site-lisp/mu4e/mu4e-main
/usr/share/emacs/site-lisp/mu4e/mu4e-meta hides /usr/share/emacs24/site-lisp/mu4e/mu4e-meta
/usr/share/emacs/site-lisp/mu4e/mu4e-draft hides /usr/share/emacs24/site-lisp/mu4e/mu4e-draft
/usr/share/emacs/site-lisp/mu4e/org-mu4e hides /usr/share/emacs24/site-lisp/mu4e/org-mu4e
/usr/share/emacs/site-lisp/mu4e/mu4e-utils hides /usr/share/emacs24/site-lisp/mu4e/mu4e-utils
/usr/share/emacs/site-lisp/mu4e/mu4e-compose hides /usr/share/emacs24/site-lisp/mu4e/mu4e-compose
/usr/share/emacs/site-lisp/mu4e/mu4e-view hides /usr/share/emacs24/site-lisp/mu4e/mu4e-view
/usr/share/emacs/site-lisp/mu4e/mu4e-lists hides /usr/share/emacs24/site-lisp/mu4e/mu4e-lists
/usr/share/emacs/site-lisp/mu4e/mu4e-actions hides /usr/share/emacs24/site-lisp/mu4e/mu4e-actions
/usr/share/emacs/24.4/site-lisp/debian-startup hides /usr/share/emacs/site-lisp/debian-startup
/usr/share/emacs24/site-lisp/cmake-data/cmake-mode hides /usr/share/emacs/site-lisp/cmake-mode
~/.emacs.d//phil/../custom hides /usr/share/emacs/24.4/lisp/custom
/usr/share/emacs/site-lisp/rst hides /usr/share/emacs/24.4/lisp/textmodes/rst
/usr/share/emacs24/site-lisp/dictionaries-common/flyspell hides /usr/share/emacs/24.4/lisp/textmodes/flyspell
/usr/share/emacs24/site-lisp/dictionaries-common/ispell hides /usr/share/emacs/24.4/lisp/textmodes/ispell

Features:
(shadow sort flyspell ispell gnus-util mail-extr emacsbug message
format-spec rfc822 mml mml-sec mm-decode mm-bodies mm-encode mail-parse
rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045
ietf-drums mm-util mail-prsvr mail-utils pp elisp-slime-nav help-mode
etags paredit whitespace idle-highlight-mode thingatpt hl-line
page-break-lines em-unix em-term term disp-table ehelp em-script
em-prompt em-ls em-hist em-pred em-glob em-dirs em-cmpl em-basic
em-banner em-alias pcomplete comint ansi-color esh-var esh-io esh-cmd
esh-opt esh-ext esh-proc esh-arg eldoc esh-groups eshell esh-module
esh-mode esh-util ido-ubiquitous ido-completing-read+ cus-edit cus-start
cus-load wid-edit winner ring smex find-file-in-project diff-mode
easymenu easy-mmode autoload advice help-fns paren edmacro kmacro
saveplace ido cl-macs cl gv cl-loaddefs cl-lib time-date tooltip
electric uniquify ediff-hook vc-hooks lisp-float-type mwheel x-win x-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment
lisp-mode prog-mode register page menu-bar rfn-eshadow timer select
scroll-bar mouse jit-lock font-lock syntax facemenu font-core frame cham
georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese hebrew greek romanian slovak czech european ethiopic
indian cyrillic chinese case-table epa-hook jka-cmpr-hook help simple
abbrev minibuffer nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote make-network-process
dbusbind gfilenotify dynamic-setting system-font-setting
font-render-setting move-toolbar gtk x-toolkit x multi-tty emacs)

Memory information:
((conses 16 148161 6857)
 (symbols 48 24391 0)
 (miscs 40 86 137)
 (strings 32 31521 6206)
 (string-bytes 1 921308)
 (vectors 16 16803)
 (vector-slots 8 457088 3415)
 (floats 8 103 100)
 (intervals 56 328 0)
 (buffers 960 12)
 (heap 1024 33431 1918))



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

bug#27361: 24.4; eshell/echo silently ignores -n argument

npostavs
Phil Hagelberg <[hidden email]> writes:

> When using eshell, the `echo' built-in doesn't respect the -n argument,
> which is supposed to suppress the trailing newline.
>
> Sometimes this is not a problem because you can see for yourself that
> eshell did the wrong thing, but if you are piping it directly to another
> command, it's easy to miss.
>
> The eshell/echo function should be changed to either accept the -n
> argument and omit the newline, or it should complain that -n is not a
> supported argument.

It's not ignored, but eshell always adds a newline before the prompt.
Furthermore, the argument has the opposite sense to the traditional
shell interpretation:

    ~/src $ echo x | od -c
    0000000   x
    0000001
    ~/src $ echo -n x | od -c
    0000000   x  \n
    0000002




Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

bug#27361: 24.4; eshell/echo silently ignores -n argument

Phil Hagelberg-2
[hidden email] writes:

> It's not ignored, but eshell always adds a newline before the prompt.
> Furthermore, the argument has the opposite sense to the traditional
> shell interpretation

Ah, I see. Yeah, doing the opposite of what the user asked for in both
cases is much worse than simply ignoring the argument when it's present.

-Phil

signature.asc (834 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

bug#27361: 24.4; eshell/echo silently ignores -n argument

Glenn Morris-3

echo -n is famously non-portable.
Perhaps eshell is trying to make a point. ;)
echo --help does document the -n behaviour, and it's been like that
since always.
With eshell-plain-echo-behavior set, -n is simply ignored.
I would have thought you must have eshell-plain-echo-behavior set
if you want anything like "standard" echo behaviour.




Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

bug#27361: 24.4; eshell/echo silently ignores -n argument

Glenn Morris-3

It seems easy to get the behaviour that you want, for the
eshell-plain-echo-behavior case, which is the only relevant one.
At the same time, we can fix eshell/printnl for that case,
to avoid the doubled newlines that it currently gives.

I don't know how to explain in --help what -n means though. :)

--- a/lisp/eshell/em-basic.el
+++ b/lisp/eshell/em-basic.el
@@ -88,7 +88,8 @@ eshell-echo
 It returns a formatted value that should be passed to `eshell-print'
 or `eshell-printn' for display."
   (if eshell-plain-echo-behavior
-      (concat (apply 'eshell-flatten-and-stringify args) "\n")
+      (concat (apply 'eshell-flatten-and-stringify args)
+      (unless output-newline "\n"))
     (let ((value
    (cond
     ((= (length args) 0) "")
@@ -126,7 +127,8 @@ eshell/printnl
   "Print out each of the arguments, separated by newlines."
   (let ((elems (eshell-flatten-list args)))
     (while elems
-      (eshell-printn (eshell-echo (list (car elems))))
+      (eshell-printn (eshell-echo (list (car elems))
+  eshell-plain-echo-behavior))
       (setq elems (cdr elems)))))
 
 (defun eshell/listify (&rest args)



Loading...