[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Failed trap ERR inside function
From: |
Chet Ramey |
Subject: |
Re: Failed trap ERR inside function |
Date: |
Fri, 12 Oct 2007 19:51:59 -0400 |
User-agent: |
Thunderbird 2.0.0.6 (Macintosh/20070728) |
Evgenij Shkrigunov wrote:
> Description:
> Failed trap ERR inside function. Below is an example of script(see comments):
>
> #!/bin/bash -E
>
> err_print() {
> RETVAL=$?
> echo "Nonzero exit: $RETVAL"
> echo "file: ${BASH_SOURCE[0]}"
> echo "line: ${BASH_LINENO[0]}"
> }
>
> trap err_print ERR
>
>
> failed_func(){
> # false must be ignored becose &&
> # but ...
> false && echo ""
> }
>
> # false must be ignored becose &&
> false && echo ""
>
> failed_func
The ERR trap is inherited by the function and ignored. The simple command
that fails and causes the ERR trap to be run is the call to `failed_func'
itself. This would be clearer if you added `echo after' as the last
command in the body of `failed_func'.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
Live Strong. No day but today.
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/