bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Exit-on-error option does not work as expected


From: Matthew Woehlke
Subject: Re: Exit-on-error option does not work as expected
Date: Tue, 17 Jul 2007 11:02:10 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.12) Gecko/20070509 Thunderbird/1.5.0.12 Mnenhy/0.7.4.0

mod.bashbug.2007-07-16@3amok.com wrote:
Script:
        #! /bin/bash
        set -e

        archive_item()
        {
                set -e
                false # this is the command that fails to archive the item
                echo 'Archived.'
        }

        delete_item()
        {
                true # this is the command that deletes the item
                echo 'Deleted!'
        }

        archive_item && delete_item

Expected output:
        <empty>

Actual output:
        Archived.
        Deleted!

The right way to do this IMO is to forget 'set -e' and do:

archive_item()
{
  set -e
  if false # command that fails to archive the item
  then echo 'Archived.'
  else return $?
  fi
}

...which causes 'archive_item' to return non-zero, so that '&& delete_item' is never executed.

--
Matthew
find / -user your -name base -print0 | xargs -0 chown us:us





reply via email to

[Prev in Thread] Current Thread [Next in Thread]