Subject: Re: discrepency beteen /bin/echo and builtin echo of /bin/sh
To: <>
From: David Laight <>
List: tech-userlevel
Date: 06/13/2002 13:55:02
> You seem to be completely missing the point.  I'll try to explain more
> slowly, and not to assume that you've read all of the standard.
> With POSIX and SUS, the terms "option", "operand", and "argument" have
> specialised meanings.  An argument is one of the strings passed as part of
> argv to a utility.  Some of these arguments contain options, some of them
> contain option-arguments, at most one of them contains the end-of-options
> delimeter, and the rest are operands.  Note that this means that no argument
> can both contain options and be an operand.  See
> <> for
> more details.

ok, I was probably being loose with these terms....

> Now, the specification for "echo" explicitly states that it shall not
> recognise "--" as the end-of-options delimiter, but as an operand.
> Thus, in the command-line "echo -- foo", there are two operands, "--" and
> "foo".

Is there any sensible rational for this?
(apart from historical precedent and paranoia)

> The interesting question is how we analyse the command-lines "echo -n foo"
> and "echo -e foo".  Specifically, are "-n" and "-e" options or operands? 
> How about in "echo -e -n foo" and "echo -n -e foo"?

or "echo -en foo" or "echo -n -n foo"

(netbsd's ksh builtin echo is particularly broken here...)

I suspect it would actually be best to 'bite the bullet' and make
echo getopts(3) conformant supporting options n, e and E.
(where an implementation may default to -E or -e).
Unfortunately the SuS (and posix?) explicitely forbid this :-(

The reason I had 3 behaviours was that the (online) SuS disallowed
all options (or first arguments of -n), and I thought that the posix
spec disallowed options other than -n.
This meant (I thought) that the current netbsd (sh builtin) echo was neither
a XSI (SuS) echo, nor posix compliant.

Some versions of echo:
netbsd	/bin/echo	-n
netbsd	sh		-n or -e
netbsd	csh		-n
netbsd	ksh		[-neE]
solaris8 (all)		expands \x
UW2	/bin/echo	-n, expands \x
UW2	sh		-n, expands \x unless /usr/ucb before /usr/bin
			in $PATH.
UW2(ATT) ksh		not sure - I've only got the source, and I'm
			not sure what gets compiled, could do many things!
			could easily depend on whether $PATH hits
			/bin/echo before anything else....


David Laight: