Subject: Re: discrepency beteen /bin/echo and builtin echo of /bin/sh
To: NetBSD Userlevel Technical Discussion List <tech-userlevel@netbsd.org>
From: Greg A. Woods <woods@weird.com>
List: tech-userlevel
Date: 06/12/2002 16:47:32
[ On Wednesday, June 12, 2002 at 15:48:57 (-0400), der Mouse wrote: ]
> Subject: Re: discrepency beteen /bin/echo and builtin echo of /bin/sh
>
> > That's just plain silly.  It is not important or necessary for "echo"
> > to support '--'.  "-n" is defined to be only recognized if it is the
> > _FIRST_ operand.
> 
> So, how do you get echo to produce the three characters '-', 'n', '\n'
> as output?

like this:

	echo '-\c'
	echo 'n'

(I often assume 'echo' will know about '\c', though you'll find tricks
to avoid this assumption in my ~/.profile)

>  For that matter, how do you take a user-supplied string
> (which might be "-n") and echo it?  (echo -n "$stuff"; echo "") seems
> awfully ugly.

Usually I just do:

	echo "" "$user_stuff"

and if a leading space is not desired, and output is to the user's TTY
(not some data file), then I use CTRL-B:

	echo " ^b" "$user_stuff"

or I use printf (perhaps from in awk if there's no printf(1))!  :-)

-- 
								Greg A. Woods

+1 416 218-0098;  <gwoods@acm.org>;  <g.a.woods@ieee.org>;  <woods@robohack.ca>
Planix, Inc. <woods@planix.com>; VE3TCP; Secrets of the Weird <woods@weird.com>