bug-bash
[Top][All Lists]
Advanced

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

Re: Executing 'return' inside RETURN trap causes function to recurse inf


From: Eduardo A . Bustamante López
Subject: Re: Executing 'return' inside RETURN trap causes function to recurse infinitely
Date: Fri, 7 Mar 2014 12:08:22 -0800
User-agent: Mutt/1.5.21 (2010-09-15)

On Fri, Mar 07, 2014 at 11:38:21AM -0800, Eduardo A. Bustamante López wrote:
> WARNING: the codes given below cause the shell to enter an infinite
> loop.
> 
> 
> Both:
> dualbus@debian:~$ bash -Tc 'f(){ :; }; trap return RETURN; f'
> ^C
> 
> and:
> dualbus@debian:~$ bash -c 'f(){ trap return RETURN; }; f'
> ^C
> 
> Cause the function call to recurse infinitely. I would understand if

By the way, I forgot to add the reason why I found this. POSIX states
the following:

| EXIT STATUS
| 
| The value of the special parameter '?' shall be set to n, an unsigned
| decimal integer, or to the exit status of the last command executed
| if n is not specified. If the value of n is greater than 255, the
| results are undefined. When return is executed in a trap action, the
| last command is considered to be the command that executed
| immediately preceding the trap action.

Reference: 
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_24

The interesting bit is 'when return is executed in a trap action,
...'. So I wanted to test that, and the easiest way I thought I could
verify if that matched, was to execute return in a RETURN trap. It's
worth noting that using --posix does not affect the outcome.

-- 
Eduardo Alan Bustamante López



reply via email to

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