I try to use tee to save output in file like:
myapp | tee log.txt
But I have a problem with checking of exit. Previous code:
myapp
if [ $? -eq 0 ]
then .....
But $? will be exit of tee! Does it possible catch exit of myapp?
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For bash, there’s a convenient special array: PIPESTATUS. The return code for
myappwould be in ${PIPESTATUS[0]} and so on.zsh has a roughly identical method.
There’s also a rather more annoying, hacky way to do it in strict bourne shells that you can read about in the comp.unix.shell FAQ.