bug-bash
[Top][All Lists]
Advanced

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

Re: trap cmd ERR (in a function) behavior not consistent


From: Chet Ramey
Subject: Re: trap cmd ERR (in a function) behavior not consistent
Date: Thu, 13 Nov 2003 17:28:23 -0500

> Machine Type: i686-pc-linux-gnu
> 
> Bash Version: 2.05b
> Patch Level: 0
> Release Status: release
> 
> Description: 
>       Using trap cmd ERR in a function leads to unexpected results,
> depending on the cmd and how the function is invoked.  For example, a
> simple echo command in the trap appears to work as expected when the
> function is invoked as a simple command (e.g.  on a line by itself),
> but the trap is ignored when the function is invoked as the condition
> of an if clause.  To illustrate, consider a function sub1 which
> contains the statement

There are two issues here:

First, the problem of the trap being effectively ignored when you put a
`return' in the trap command in sub1.  This is a bug -- the shell doesn't
clean up after itself well enough when a `return' is executed while the
shell is executing the trap command.  This has been fixed for the next
version.

Second, the ERR trap is executed under exactly the same conditions as
when the shell would exit if `set -e' were enabled.  Those are listed in
the man page.  Being part of a command executed as the test in an `if'
statement is one of the conditions under which the shell will not exit.
The full list is in the man page.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet )
                                                Live...Laugh...Love
Chet Ramey, ITS, CWRU    chet@po.cwru.edu    http://tiswww.tis.cwru.edu/~chet/




reply via email to

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