perl/script and retval

Giorgos Keramidas keramida at
Sun Apr 8 18:07:46 UTC 2007

On 2007-04-08 17:38, Olivier Regnier <oregnier at> wrote:
> Hello,
> I written a small script in sh :
> # Downloading doc files
> echo "===> Downloading doc files"
> /usr/bin/csup $doc_supfile
> if [ $RETVAL != 0 ]; then
>    echo "abort"
>    exit 0
> fi

This script has a minor bug.  There is no != test for numeric values in
sh(1) scripts.  See below for a slightly larger shell script with some
reusable parts, which works probably better.

> I want to rewritte this code in perl script.
> my $retval=0;
> my $doc_supfile="/etc/doc-supfile";
> # Downloading doc files
> print "===> Downloading doc files\n";
> system("/usr/bin/csup $doc_supfile
> if (! $retval) {
> print "abort";
> exit;
> }
> I don't know what happened with retval but that doesn't work correctly.

Missing quotes at the end of the system("... line?

In this case, it's quite easy to run the command in a simple shell
script.  WHy do you *have* to rewrite everything in Perl?  If it's
because you want to learn how something like this could be done in
Perl too, that's ok.  But it the reason is because "Perl is faster",
"Perl is safer", or some other similar 'optimization' related reason,
then just don't :)

A small shell script can go very far along the way, i.e.:


        echo "===> $*"

        echo >&2 "ERROR: $*"
        exit $retval

        date '+%Y-%m-%d %H:%M:%S'

        if [ -z "${doc_supfile}" ]; then
            err 1 "no supfile for 'doc' collection"

        msg "Download of 'doc' collection started at" `timestamp`
        /usr/bin/csup "$doc_supfile"
        msg "Download of 'doc' collection finished at" `timestamp`

    get_doc_files /root/supfiles/doc-supfile
    if [ $? -ne 0 ]; then
        err 1 "get_doc_files failed."

More information about the freebsd-questions mailing list