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

Bug#490605: debian-policy: please discourage the usage of echo -n, and echo in general



On Thursday 04 June 2009 01:28:01 Giacomo Catenazzi wrote:
> Raphael Geissert wrote:
> I think we could forbid "echo -n" on maintainer and other scripts, but
> allow it on init.d scripts.

Like Julien said, I think making different recommendations is a bad idea.

> Rationale:
> - portability is more important on other scripts, and it is also not so
>   frequent to use echo -n

No, not really. In a large project the interest is to be as portable as 
possible, diverging as less as possible to support different ecosystems. And 
that applies to all kind of code.

> > Yes, printf.
>
> It is not an alternative:
> - It is ugly

You say "it is ugly", I say "it is pretty", and none of us can be proved right 
or wrong because it is a subjective statement. Rephrasing or otherwise 
omitting that statement would be better for the sake of the discussion.

> - it is not on root partition

Only when not implemented as a shell built-in (which is very very rare, and I 
think of all the shell interpreters in Debian only posh doesn't implement it 
because it is not required by policy.) However, if it is a real concern then 
we could request printf to be installed in /bin.

> Most of people understand "echo -n", but I don't know if all people
> understand fully printf.  Mixing echo and printf is ugly.

printf exists as-is or has an equivalent in most programming languages, so I 
doubt a more or less formed programmer won't know how printf works.
OTOH, echo -n is just a bashism, not even an XSIsm[1], and the option name 
doesn't tell much about what it does.

Not to mention that this discussion is not only about *discouraging* (not  
forbidding!) the -n option, but when passing a string with backlashes to 
echo.

> Anyway the standard are helper tools, not tools to make difficult the live
> of user and maintainer.

'echo' is a portability nightmare if not used properly, I don't know how you 
could say it helps.

> See for example the recent discussion about ext3, 
> see the old discussion about tar (tar is not in POSIX, people should use
> 'pax')

I think that's irrelevant, and for the sake of this discussion I would like if 
you could stop giving examples of how "we are not POSIX." The reasons for 
that, I think, are pretty obvious.

>
>
> BTW I think this is incorrect:
> $ POSIXLY_CORRECT=1 bash -c "echo -n line one; echo line two";
> > line oneline two

Policy doesn't make any exeption, so the behaviour follows what policy 
mandates. It is just another example of why we can't rely on echo.

[1] " On XSI-conformant systems, if the first operand is -n, it shall be 
treated as a string, not an option."

Regards,
-- 
Raphael Geissert - Debian Maintainer
www.debian.org - get.debian.net



Reply to: