I want to log the output of a script; hence, I pipe from the block containing most of my code to tee. However, I have trouble with variables' values being lost when the pipeline exits. For example:
{
(exit 3) # do something
result=$?
} 2>&1 | tee -ia /var/log/action.log
exit "$result" # this needs to also exit with status 3
How do I return the value set inside the piped code block?