bug-sh-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Printing "-n" with the echo command


From: era+gmane
Subject: Re: Printing "-n" with the echo command
Date: 21 Jan 2004 16:13:47 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

On Wed, 21 Jan 2004 10:39:29 +0100, <address@hidden> posted to
gmane.comp.gnu.sh-utils.bugs:
 > I understand "-n" is an option of the "echo" command, but could it be
 > possible to print it as regular text when placed between quotes ?

Quotes are handled by the shell, and never seen by echo. Unless you
actually want

  echo '"-n"'

to echo -n instead of "-n" in which case you can submit a new bug
report about how it would be nice if there was a way to actually get
the double quotes included in the output. Catch 22.

The conventional answer to this one is to feed the output to sed or
some such.

  echo X-n | sed -e 's/^X//'

It's not elegant but in this case I'm afraid backwards compatibility
is more important than elegance. If you want to break backwards
compatibility, you might as well supply your own hand-optimized Bison
version of Hello World to output text.

  yes -n | head -1
  echo Xn | tr X -
  perl -le 'print "-n"'
  emacs --batch --no-init-file --no-site-file --eval '(message "-n")'

(The last one is actually surprisingly fast :-)

Hope this helps,

/* era */

-- 
formail -s procmail <http://www.iki.fi/era/spam/ >http://www.euro.cauce.org/
cat | more | cat<http://www.iki.fi/era/unix/award.html>http://www.debian.org/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]