I want to execute a long running command in Bash, and both capture its exit status, and tee its output.
So I do this:
command | tee out.txt ST=$?
Dumb solution: Connecting them through a named pipe (mkfifo). Then the command can be run second.
mkfifo pipe tee out.txt < pipe & command > pipe echo $?