While tracing a function in bash
, I can return non-zero value (say,1
) from by DEBUG
trap
handler to skip the execution of the next line.
Also, I can return the value 2
to execute a return
statement to return out of the function without executing the rest of the function body
However, I would like to be able to step out of the current function, not by `return'ing, but by executing the remainder of the function body in just a single shot (instead of executing it line-by-line till the end of its body).
Is this possible?
Tedious sure, but it seems this can be done with the existing callstack information provided by Bash.
Here's how.
Keep executing your DEBUG
trap handler till you reach the next callstack frame, F2, sitting right under the current one, F1, and stop on a line number that is greater than or equal to the BASH_LINENO
saved in F2. The '... or equal to' check is required to address recursive calls.