Let's say that I have a function named nested which returns a String and an error code, this function is then used by the main function to assign the returned value to a variabe.
Sample code
function main() {
local variable=$(nested)
echo $?
echo $variable
}
function nested() {
echo "Value"
return 1
}
main
Expected output
1
Value
Actual output
0
Value
How do I fix this and/or what's the proper way to gather the exit code of a function that is enclosed by $(...) ?