Subject: Re: discrepency beteen /bin/echo and builtin echo of /bin/sh
To: None <firstname.lastname@example.org>
From: Greg A. Woods <email@example.com>
Date: 06/08/2002 15:48:42
[ 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....
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.
Of course SuSv2 goes on to say:
It is not possible to use echo portably across all systems that are
not XSI-conformant unless both -n (as the first argument) and
escape sequences are omitted.
The printf utility can be used portably to emulate any of the
traditional behaviours of the echo utility as follows:
* The XSI echo is equivalent to:
printf "%b\n" "$*"
* The BSD echo is equivalent to:
if [ "X$1" = "X-n" ]
printf "%s" "$*"
printf "%s\n" "$*"
New applications are encouraged to use printf instead of echo.
So maybe printf should be a builtin and 'echo' be a function or alias
that does the emulation as above.....
[[ Some people say /etc/inittab is the defining feature of AT&T UNIX,
but they're only trying to misdirect you from the real truth: the
defining feature of AT&T UNIX is a sane 'echo' implementation! :-) ]]
> The man page ought to list the builtins, there are some subtle
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).
> 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 $?
$ type echo
echo is a shell builtin
Greg A. Woods
+1 416 218-0098; <firstname.lastname@example.org>; <email@example.com>; <firstname.lastname@example.org>
Planix, Inc. <email@example.com>; VE3TCP; Secrets of the Weird <firstname.lastname@example.org>