program to generate data helpful in finding duplicate large files
Cameron Simpson
cs at zip.com.au
Fri Sep 19 20:27:45 EDT 2014
On 19Sep2014 23:59, Chris Angelico <rosuav at gmail.com> wrote:
>On Fri, Sep 19, 2014 at 11:32 PM, David Alban <extasia at extasia.org> wrote:
>> if you omit the exit statement it in this example, and
>> $report_mode is not set, your shell program will give a non-zero return code
>> and appear to have terminated with an error. in shell the last expression
>> evaluated determines the return code to the os.
>
>IMO that's a terrible misfeature. If you actually want the return
>value to be propagated, you should have to say so - something like:
>
>#!/bin/sh
>run_program
>exit $?
>
>Fortunately, Python isn't like that.
IMO, it is good that the shell is like that. It isn't Python.
A great many small shell scripts are one liner wrappers, and this serves them
well. A great many more are a lot of prep work followed by a major (and final)
command. These are also served well.
There is the hazard where someone careless goes:
... main script ...
echo "script failed!" >&2
and accidentally exits with 0 (success).
For further fun, I run my shell scripts with the -e and -u options turned on.
And of course for complicated stuff I usually maintain a $xit variable, setting
it to 1 when something goes blam, and finishing such scripts with:
exit $xit
But for wrappers, the shell default exit design is handy.
Cheers,
Cameron Simpson <cs at zip.com.au>
From the back of the research lab, the sound of a large metallic pile of
loose objects collapsing, accompanied by a loud "Aaaaiiieeyyrrgghhh!!" from
George. A few seconds of silence, then: "I'll have to call you back."
More information about the Python-list
mailing list