Set the bash environmental variable "PROMPT_COMMAND" to save the output of the last executed command to variable "LAST" and file '/tmp/x"
PROMPT_COMMAND='LAST="`cat /tmp/x`"; exec >/dev/tty; exec > >(tee /tmp/x)'