choice of control operators in scripts

Cristian Ionescu-Idbohrn cristian.ionescu-idbohrn at axis.com
Wed May 14 06:41:07 UTC 2008


On Tue, 13 May 2008, Denys Vlasenko wrote:

> Basically, you are saying that
>
> foo && bar
>
> will have exitcode !=0 if foo fails, while
>
> ! foo || bar
>
> will have exitcode 0 if foo fails.

Yes.

> And you want exitcode to be !=0 only if "real" error happened,
> because you like running your scripts with "set -e".

Yes.  But I would rephrase that and to ``because it should be possible
to run the scripts with "set -e" too, and have revealed real errors''.

> Therefore you want to use || in cases where foo sometimes failing
> is expected.

Tes.

> I'd say that the desire to run scripts with "set -e" needs
> to be explained.

The best explanation I can produce is that I think the interesting status
code after a test ('[') statement is executed is not the status of the
test itself, but the status returned by the right side of that test.

> I am not convinced that it is needed,
> and that the effort needed to make all shell scripts
> in bbox tree to run that way is worthwhile.

Well, robust test scripts is worth some effort.  You want to find fast and
focus on the real problem.

> The patch contains unrelated changes. Can you send the patch which ONLY
> replaces "foo && bar" with "negation_of_foo || bar"?

Please see attached.


Cheers,

-- 
Cristian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: testsuite.patch
Type: text/x-diff
Size: 2840 bytes
Desc: 
Url : http://lists.busybox.net/pipermail/busybox/attachments/20080514/97f9dd53/attachment.bin 


More information about the busybox mailing list