bug-bash
[Top][All Lists]
Advanced

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

Re: set -e (errexit) does not work in subfunctions when a return result


From: Chet Ramey
Subject: Re: set -e (errexit) does not work in subfunctions when a return result is checked
Date: Sun, 27 Dec 2009 21:40:39 -0500
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.5) Gecko/20091204 Thunderbird/3.0

On 12/24/09 3:35 PM, Krzysztof Oledzki wrote:

> Bash Version: 4.0
> Patch Level: 35
> Release Status: release
> 
> Description:
>         set -e (errexit) does not work in subfunctions when
>         caller checks for a return result
> 
> Repeat-By:
> ---cut here ---
> #!/bin/sh
> 
> f() {
>   set -e
>   ls this-file-does-not-exist
>   echo "should not hapen"
> }
> 
> echo "Try #1"
> f || echo "failed"
> 
> echo "Try #2"
> f

Since the first call to f takes place on the left of a `||', set -e has
is ignored during its execution, and enabling it has no effect (though,
since settings are global, it remains enabled after the function returns).

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/




reply via email to

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