[Rear-users] Imporant change regarding the use of "return"

Schlomo Schapiro schlomo at schapiro.org
Wed Jul 1 09:36:58 CEST 2009


to catch scriptlets that fail due to syntax errors the Source function now
checks the return code of all sourced files. The new behaviour is that ReaR will
fail with a BugError message if any sourced script returns non-0.

As a consequence it is now important to pay attention to the potential exit
codes of scripts, mostly this concerns two places

1) intended returns triggered by "return". The bash help says

return: return [n]
    Return from a shell function.

    Causes a function or sourced script to exit with the return value
    specified by N.  If N is omitted, the return status is that of the
    last command executed within the function or script.

It is therefore important to always use "return 0" and not just "return" because
in our most common usage example of "test <something> || return" the return code
would be 1 since the "test" FAILED and return returns that fail code and thus
the entire script would have failed.

2) the last command in a script file

Since the result of a sourced script is the return code of the last command
executed one must make sure that it is always true (and handle error situations
properly in the script). If in doubt, simple add a "true" as the last command.

In my upcoming commit I fixed all known occurences of return and checked as much
as possible. Nevertheless you should be watching for BugError messages
concerning scripts and suspect this issue first.


More information about the rear-users mailing list