Within bash, how can a RETURN
handler access the current return code?
For example
#!/usr/bin/env bash
function A() {
function A_ret() {
# How to access the return code here?
echo "${FUNCNAME} ???"
}
trap A_ret RETURN
echo -n "${FUNCNAME} returning code $1 ... "
return $1
}
A 1
This prints
A returning code 1 ... A_ret ???
I would like it to print
A returning code 1 ... A_ret 1
How can A_ret
access A
return code?
Similar to this stackoverflow question Get the exitcode of the shell script in a “trap EXIT”.