Solved

How do I use tee but retain the exit result code!

Posted on 2004-10-25
289 Views
Last Modified: 2013-11-17
I have a script called script1 which returns a result code. However the script itself also calls other scripts which frequently display important messages we need to capture. Unfortunately

script1 | tee -a LOGFILE

captures the messages, but loses the result code, because the act of calling tee resets it to 0. We need to be able to both see the messages at runtime and also keep them stored in LOGFILE. How can I still do both of these and yet not destroy the rc from script1?  
0
Question by:hughm
    1 Comment
     
    LVL 60

    Accepted Solution

    by:
    #!/bin/ksh
    (script1 ; (echo $? >.temp-id) ) | tee -a WHATEVER
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Product Review - Android Remix

    Come along for the ride with our Senior Product Manager, Brian Matis, as he reviews the Android Remix.

    My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
    Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now