Subject: Re: discrepency beteen /bin/echo and builtin echo of /bin/sh
To: NetBSD-current Discussion List <current-users@NetBSD.ORG>
From: David Laight <david@l8s.co.uk>
List: current-users
Date: 06/08/2002 22:25:54
On Sat, Jun 08, 2002 at 03:48:42PM -0400, Greg A. Woods wrote:
> [ On Saturday, June 8, 2002 at 20:05:48 (+0100), David Laight wrote: ]
> > Subject: Re: discrepency beteen /bin/echo and builtin echo of /bin/sh
> >
> > It might? be worth including print (aka ksh), you don't always want
> > the complexity of printf (esp. since is isn't a builtin).
> 
> I'd VERY much rather see /bin/echo and /bin/sh's built-in echo be
> conformant with SuSv2 instead (since it provides most of the
> capabilities of the ksh "print" builtin without any of the portability
> headache), though I guess getting a bunch of *BSD-heads to agree to give
> up "echo -n", even after all these decades, is rather fruitless, so we'd
> have to keep that, and if we do that then we might as well add '-r/-E'
> and a no-op '-e' just in case too....

Certainly the SuS version is generaly more useful - I like to be
able to generate control characters from within the shell.

Given that the (netbsd) sh builtin has always had -e (look at CVS)
I don't actually see any reason not to document it, and make /bin/echo
work the same way.  (also 'echo -e -n fred' ought to output fred
without a newline, not "-n fred").

The least painful change would (probably) be to add a ksh style
print to sh (and csh).

> Oddly the pdksh man page suggests *BSD echo has a '-e' option that makes
> it behave much more like SuSv2's echo, though "our" echo is missing this
> feature.....  Luckily '-e' is a no-op in ksh.

The builtin one does - try it....

> > The man page ought to list the builtins, there are some subtle
> > differences.
> 
> It does.
> 
>    Builtins
> 
>      This section lists the builtin commands which are builtin because they
>      need to perform some operation that can't be performed by a separate pro-
>      cess. In addition to these, there are several other commands that may be
>      builtin for efficiency (e.g.  printf(1), echo(1), test(1), etc).

That says 'may', printf isn't, echo and test are, don't know about etc.

> >   eg what happens when a redirect fails (not checked
> > that on netbsd - you need a device driver that rejects opens).
> 
> $ echo foo > /no/such/file
> cannot create /no/such/file: directory nonexistent
> $ echo $?
> 2
> $ type echo
> echo is a shell builtin

I did say I hadn't tried it on netbsd....

(actually I might be thinking of a different problem - I remember
having trouble forcing the shell to open a device, and having
the script exit if a redirect on a builtin failed...)


	David

-- 
David Laight: david@l8s.co.uk