bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: sed


From: Stephane Chazelas
Subject: Re: sed
Date: Wed, 14 Feb 2007 08:33:31 +0000
User-agent: Mutt/1.5.6i

On Tue, Feb 13, 2007 at 10:30:54PM +0100, Ralf Wildenhues wrote:
> Hello Stephane, all,
> 
> * Stephane Chazelas wrote on Tue, Feb 13, 2007 at 10:07:36AM CET:
> > 
> > 1- "echo" is a command to expand the \b, \n, \r... not the
> > command to display some text verbatim
> 
> Not necessarily.

Depends indeed. For Unix conformant echos, it's required, while
for POSIX (a subset of Unix), it's unspecified. So, if your
script is to be ported only to Unix conformant systems, then you
may rely on echo '\v' outputting <VT><LF>. If not, you can't
rely on anything. That's why POSIX and Unix (the SUS) advice
against using echo, but use printf instead.

> 
> > echo '\v'
> > 
> > outputs a vertical tab followed by a line feed.
> 
> Not my shell's echo, no.  That outputs backslash v newline.  Not being
> able to rely on this is exactly one reason to avoid echo.

I'd bet your shell is bash. bash only claims for POSIX
conformance. However bash's echo is not even POSIX conformant as
"echo -e" doesn't output "-e<LF>".

> 
> > You want the POSIX printf '%s\n' or the ksh/zsh specific print
> > -r --.
> 
> Yep.  However in the real world (that one that exists next to
> standards), existing printf programs can have bugs with long
> arguments, or with \045.  If present, printf is certainly
> preferable to echo, though.

printf will exist if you're in a POSIX environment. To my
knowledge, no printf implementation has problems with:

printf '%s\n' "$VAR"

(unless GNU's one did with printf '%s\n' --help? But that one
wouldn't occur in a POSIX environment (with POSIXLY_CORRECT set)
I guess).

-- 
Stéphane




reply via email to

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