bug-bash
[Top][All Lists]
Advanced

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

Executing 'return' inside RETURN trap causes function to recurse infinit


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

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
this is labeled as a feature, rather than a bug (in the sense that
the user shouldn't be putting return inside a return trap :), so one
can safely assume that if they did it, it's because they wanted the
infinite recursion).

Though, I think the following 2 approaches would be better/more
consistent.

(1) treat the execution of return inside a RETURN trap as an error,
like when 'return' is called outside a function/sourced script.

(2) treat return specially when it's executed inside a return trap,
making it return immediately from the trap.



dualbus@debian:~$ bash --version
GNU bash, version 4.3.0(1)-rc2 (x86_64-unknown-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

-- 
Eduardo Alan Bustamante López



reply via email to

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