Capture STDOUT, STDERR and return status in shell variables
This second answer ( the one with the banana function ) shows how to capture all three to variables in bash without needing tmp files
https://stackoverflow.com/questions/13806626/capture-both-stdout-and-stderr-in-bash
----
banana() {
echo "banana to stdout"
echo >&2 "banana to stderr"
return 42
}
----
----
. <({ berr=$({ bout=$(banana); bret=$?; } 2>&1; declare -p bout bret >&2); declare -p berr; } 2>&1)
----
Then check values of $bout, $berr, $bret