From: Seebs on
On 2010-06-12, News123 <news1234(a)free.fr> wrote:
> Why would you care????

Because unexpected behaviors can cause serious problems.

> i don't use --version in my scripts
> and when I type
> false --version, then I don't care for it's exit status.

One idiom one occasionally sees is:

: ${foo:=$bar}

or

true ${foo:=$bar}

which serves as a way to expand a variable for the side-effects of the
expansion. This idiom can have unexpected results if ANY argument to
true can cause it to do something.

> You can always construct failing scenario, but I cannot imagine whenever
> an exit code of 0 would have killed me or my scripts.

If you were counting on false returning false, it could cause surprises.

On the other hand, more likely is that the output would cause problems.
One of the most obnoxious bits of code I ever encountered was a configure
script (not an autoconf one) which attempted to test for compiler
functionality as follows:

$CC <options> -o foo.o foo.c > conf.out 2>&1
if [ -s conf.out ]; then echo >&2 "Not supported."; fi

This assumed that the only circumstances under which a compiler could
ever yield a message of any sort would be compilation failure; however,
we had a compiler which, in a development environment, would sometimes
print a warning that it hadn't found a license manager. It was a purely
advisory warning, and compilation succeeded.

I am sure there is other code out there which will blow up if programs
which are not expected to produce output to.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: Randal L. Schwartz on
>>>>> "Seebs" == Seebs <usenet-nospam(a)seebs.net> writes:

Seebs> One works 100% of the time, regardless of anything users could
Seebs> ever provide as input.

Unless "printf" isn't installed. It's a relatively recent addition to
Unix, and therefore, non-portable, while every version of Unix I've used
has had echo (although there are variations in argument interpretation).

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn(a)stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
From: Sven Mascheck on
Randal L. Schwartz wrote:

> Unless "printf" isn't installed. It's a relatively recent
> addition to Unix, and therefore, non-portable,

printf was introduced with 9th edition and then added to more
widely distributed Unix flavours with 4.3BSD-Reno and SVR4.
(And apart from traditional portability, it's required by
POSIX/SUSv2.)

I believe the only possibly relevant systems nowadays which
are missing it are SunOS 4 and SVR3 derivatives.
--
http://www.in-ulm.de/~mascheck/various/echo+printf/
From: Seebs on
On 2010-06-12, Randal L. Schwartz <merlyn(a)stonehenge.com> wrote:
>>>>>> "Seebs" == Seebs <usenet-nospam(a)seebs.net> writes:
>Seebs> One works 100% of the time, regardless of anything users could
>Seebs> ever provide as input.

> Unless "printf" isn't installed. It's a relatively recent addition to
> Unix, and therefore, non-portable, while every version of Unix I've used
> has had echo (although there are variations in argument interpretation).

You echo my own thoughts, and those of my technical reviewer. I thought it
was a BSD introduction, and I believe he thought it was a Linuxism. We
both thought it was not particularly portable.

Then we actually TESTED it. And we have found nothing -- no SVRx, no
BSD, no Linux -- which lacks it, except SunOS 4.1, or things even older
than that.

"Relatively recent", it turns out, appears to be upwards of twenty years
ago. Tru64, OSF/1, Solaris, BSD, Linux, you name it. It helps, of course,
that it's a built-in in at least one common shell.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: Chris F.A. Johnson on
On 2010-06-13, Seebs wrote:
> On 2010-06-12, Randal L. Schwartz <merlyn(a)stonehenge.com> wrote:
>>>>>>> "Seebs" == Seebs <usenet-nospam(a)seebs.net> writes:
>>Seebs> One works 100% of the time, regardless of anything users could
>>Seebs> ever provide as input.
>
>> Unless "printf" isn't installed. It's a relatively recent addition to
>> Unix, and therefore, non-portable, while every version of Unix I've used
>> has had echo (although there are variations in argument interpretation).
>
> You echo my own thoughts, and those of my technical reviewer. I thought it
> was a BSD introduction, and I believe he thought it was a Linuxism. We
> both thought it was not particularly portable.
>
> Then we actually TESTED it. And we have found nothing -- no SVRx, no
> BSD, no Linux -- which lacks it, except SunOS 4.1, or things even older
> than that.
>
> "Relatively recent", it turns out, appears to be upwards of twenty years
> ago. Tru64, OSF/1, Solaris, BSD, Linux, you name it. It helps, of course,
> that it's a built-in in at least one common shell.

It's a builtin in all the most common shells: bash, ksh93, dash,
BSD's sh.

--
Chris F.A. Johnson, author <http://shell.cfajohnson.com/>
===================================================================
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)