bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: echo "-e" produces no outputs


From: Stephane CHAZELAS
Subject: Re: echo "-e" produces no outputs
Date: Mon, 20 Jul 2009 09:24:12 +0100
User-agent: Mutt/1.5.16 (2007-09-19)

2009-07-19 21:07:20 -0400, Chet Ramey:
[...]
> > Note that it's a known non POSIX-conformance of bash.
> > 
> > POSIX is explicit that
> > 
> > echo -e
> > 
> > Should output "-e\n".
> 
> That's why bash has the `xpg_echo' option.  You can build bash in such
> a way that it's always enabled.
[...]

Well, that doesn't help when you intend to write a portable
script.

If you write a script that has "echo -e", POSIX guarantees that
it outputs "-e\n" as long as you're on a POSIX system in a POSIX
environment.

It's hardly documented anywhere that for instance, on Linux
(where sh is generally bash based), to get into a POSIX
environment, you would need to have
"SHELLOPTS=xpg_echo" in your environment.

Anyway, note that xpg_echo doesn't turn on POSIX conformance:

$ ./bash --norc
bash-4.0$ shopt -s xpg_echo
bash-4.0$ echo -e

bash-4.0$ echo $BASH_VERSION
4.0.0(1)-release
bash-4.0$

(same with 3.2).

"xpg_echo" turns on Unix conformance only for arguments to echo
that contain "\"s (and the behavior for those is unspecified 
by POSIX, that's part of the XSI extension).

What POSIX says is that:

echo -n xxxx
And
echo 'xxx\yyy'

are unspecified.

The rest is clearly specified.

Unix specifies echo fully.

echo -n
should output "-n<LF>"

echo '\t\c'
should output "<Tab>"

Note that bash conforms to the LSB on this which allows any
option to "echo". I wouldn't be surprised if future versions of
POSIX did the same as in effect, many shell implementations
beside bash do support other options beside "-n".

regards,
Stephane




reply via email to

[Prev in Thread] Current Thread [Next in Thread]