I am looking for a way to do this:
when I execute a script, I want to see msg(err and normal) in the shell and log them to file at the same time.
But I can't use order tee, because I want to know if last order execute successfully.
[root@CS-101 ~]# foo
bash: foo: command not found...
[root@CS-101 ~]# echo $?
127
[root@CS-101 ~]# foo | tee -a msg.txt
bash: foo: command not found...
[root@CS-101 ~]# echo $?
0