Subject: Re: discrepency beteen /bin/echo and builtin echo of /bin/sh
To: None <current-users@NetBSD.ORG>
From: Greg A. Woods <firstname.lastname@example.org>
Date: 06/09/2002 10:52:38
[ On Sunday, June 9, 2002 at 12:43:04 (+0100), Ben Harris wrote: ]
> Subject: Re: discrepency beteen /bin/echo and builtin echo of /bin/sh
> No. Any option aside from -n is specifically disallowed by both
> POSIX.2-1992 and the forthcoming corrigendum to POSIX-2001. This means that
> "echo -e foo" MUST send "-e foo\n" to stdout.
Yeah, and POSIX is god. I'd much rather stick to SuSv2 for anything
"real". At least it's more practical and pragmatic. POSIX is stuck in
the early 1980's and will undoutably stay there for decades to come,
esp. if ISO keeps oversight on it. POSIX never was practical, not ever,
However, I will note the copy of the D11.2 draft I have didn't go so far
as you say the final 1992 edition did. It only disallows '--'. It
allows any options, specifically un-defines the behaviour of '-n' as the
first option (and un-defines the behaviour of backslashes in any
strings), but doesn't require any options (nor does it require support
Are you sure you're not mis-reading the 1992 edition?
[[ starting page 475, P1003.2/D11.2 1991 ]]
4.19 echo - Write arguments to standard output
echo [string ...]
The echo utility shall write its arguments to standard output, followed
by a <newline> character. If there are no arguments, only the <newline>
character shall be written.
The echo utility shall not recognize the -- argument in the manner
specified by utility syntax guideline 10 in 2.10.2; -- shall be
recognized as a string operand.
Implementations need not support any options.
The following operands shall be supported by the implementation:
string A string to be written to standard output. If the first
operand is "-n" or if any of the operands contain a
backslash (\) character, the results are implementation
4.19.5 External Influences
220.127.116.11 Standard Input
18.104.22.168 Input Files
22.214.171.124 Environment Variables
The following environment variables shall affect the execution of echo:
LANG This variable shall determine the locale to use for
the locale categories when both LC_ALL and the
corresponding environment variable (beginning with
LC_) do not specify a locale. See 2.6.
LC_ALL This variable shall determine the locale to be used
to override any values for locale categories
specified by the settings of LANG or any
environment variables beginning with LC_.
LC_MESSAGES This variable shall determine the language in which
diagnostic messages should be written.
126.96.36.199 Asynchronous Events
4.19.6 External Effects
188.8.131.52 Standard Output
The echo utility arguments shall be separated by single <space>s and a
<newline> character shall follow the last argument.
184.108.40.206 Standard Error
Used only for diagnostic messages.
220.127.116.11 Output Files
4.19.7 Extended Description
4.19.8 Exit Status
The echo utility shall exit with one of the following values:
0 Successful completion.
>0 An error occurred.
4.19.9 Consequences of Errors
4.19.10 Rationale. (This subclause is not a part of P1003.2)
As specified by this standard, echo writes its arguments in the simplest
of ways. The two different historical versions of echo vary in fatal
The BSD echo checks the first argument for the string "-n", which causes
it to suppress the <newline> character that would otherwise follow the
final argument in the output.
The System V echo does not support any options, but allows escape
sequences within its operands:
\a Write an <alert> character.
\b Write a <backspace> character.
\c Suppress the <newline> character that otherwise follows the
final argument in the output. All characters following the \c
in the arguments are ignored.
\f Write a <form-feed> character.
\n Write a <newline> character.
\r Write a <carriage-return> character.
\t Write a <tab> character.
\v Write a <vertical-tab> character.
\\ Write a backslash character.
Write an 8-bit value that is the 1-, 2-, or 3-digit octal number
It is not possible to use echo portably across these two implementations
unless both -n (as the first argument) and escape sequences are omitted.
The printf utility (see 4.50) can be used to portably emulate any of the
traditional behaviors of the echo utility as follows:
- The System V echo is equivalent to:
printf "%b\n" "$*"
- The BSD echo is equivalent to:
if [ "X$1" = "X-n" ]
printf "%s" "$*"
printf "%s\n" "$*"
The echo utility does not support utility syntax guideline 10 because
existing applications depend on echo to echo all of its arguments, except
for the -n option in the BSD version.
New applications are encouraged to use printf instead of echo. The echo
utility has not been made obsolescent because of its extremely widespread
use in existing applications.
Copyright c 1991 IEEE. All rights reserved.
This is an unapproved IEEE Standards Draft, subject to change.
478 4 Execution Environment Utilities
Greg A. Woods
+1 416 218-0098; <email@example.com>; <firstname.lastname@example.org>; <email@example.com>
Planix, Inc. <firstname.lastname@example.org>; VE3TCP; Secrets of the Weird <email@example.com>