UNIX for Dummies Questions & Answers

This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in this forum UNIX for Beginners Questions & Answers

exit status of command in a pipe line

 

 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-12-2004
topcat8 topcat8 is offline
Registered User
 
Join Date: Jul 2003
Last Activity: 11 September 2006, 4:50 AM EDT
Location: London, England
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
exit status of command in a pipe line

Hi,

I am trying to test the exit status of the cleartool lsvtree statement below, but it doesn't seem to be working due to the tail pipe, which it is testing instead. Is there a way around this without adding a tonne of new code?
Code:
   cleartool lsvtree $testlocation/$exe_name | tail -15
   #exit out if not file not in dir
   if [ $? -ne 0 ]; then
          echo "Error: File not in test or application area"
          exit 1
   fi

Thanks
Cath

added code tags for readability --oombera

Last edited by oombera; 02-18-2004 at 11:29 AM..
Sponsored Links
    #2  
Old 02-12-2004
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
 
Join Date: May 2001
Last Activity: 24 March 2008, 9:43 PM EDT
Location: Chicago IL, USA
Posts: 1,006
Thanks: 0
Thanked 2 Times in 1 Post
unfortunetly not that i have found.

i also hit that wall when i do certin stuff.
Sponsored Links
    #3  
Old 02-12-2004
Perderabo's Unix or Linux Image
Perderabo Perderabo is offline Forum Advisor  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 26 February 2016, 12:31 PM EST
Location: Ashburn, Virginia
Posts: 9,930
Thanks: 63
Thanked 474 Times in 272 Posts
This depends on the shell. ksh can smash through that wall by moving the "tail -15" to a co-process. I don't know that cleartool command so I'll use "cat /etc/passwd" for my example:
Code:
#! /usr/bin/ksh
exec 4>&1
tail -5 >&4 |&
exec >&p
cat /etc/passwd
exitcode=$?
exec >&- >&4
wait
echo exitcode = $exitcode
exit 0

    #4  
Old 02-12-2004
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
 
Join Date: May 2001
Last Activity: 24 March 2008, 9:43 PM EDT
Location: Chicago IL, USA
Posts: 1,006
Thanks: 0
Thanked 2 Times in 1 Post
something says i shouldnt have skipped that section on file handles.
Sponsored Links
    #5  
Old 02-04-2006
here2learn here2learn is offline
Registered User
 
Join Date: Nov 2003
Last Activity: 29 September 2008, 2:15 PM EDT
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
As usual, very ingenious solution Perderabo.

Would there be any way possible to utilize xargs to facilitate this same requirement?
Sponsored Links
    #6  
Old 02-04-2006
tmarikle tmarikle is offline Forum Advisor  
Registered User
 
Join Date: Jan 2005
Last Activity: 27 September 2011, 12:36 PM EDT
Posts: 683
Thanks: 0
Thanked 4 Times in 4 Posts
Quote:
Originally Posted by Perderabo
This depends on the shell. ksh can smash through that wall by moving the "tail -15" to a co-process. I don't know that cleartool command so I'll use "cat /etc/passwd" for my example:
Code:
#! /usr/bin/ksh
exec 4>&1
tail -5 >&4 |&
exec >&p
cat /etc/passwd
exitcode=$?
exec >&- >&4
wait
echo exitcode = $exitcode
exit 0

I use this technique as well however, on occassion, I'll use the following, if I know that I'll be parsing the output anyway:
Code:
set -A ARRAY $(
    somecommand
    print RC=$?
)

for i in ${ARRAY[@]}
do
     case $i in
        RC*) ... ;;
        whateverelse) ... ;;
     esac
done

Sponsored Links
    #7  
Old 02-04-2006
reborg's Unix or Linux Image
reborg reborg is offline Forum Advisor  
Administrator Emeritus
 
Join Date: Mar 2005
Last Activity: 29 March 2012, 7:00 PM EDT
Location: Ireland
Posts: 4,464
Thanks: 0
Thanked 14 Times in 12 Posts
Ok, I'm on a PC with no shell access at them moment, and it's not very elegant but this should also work.

Code:
(cat /etc/passwd 2> /dev/null || \
        echo "Error: File not in test or application area" ; \
        exit 1 )| tail -15;

Sponsored Links
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Check the exit status in a pipe call Rkolbe Shell Programming and Scripting 7 10-05-2011 04:39 PM
Logins command exit status is 236 not 0 parkea2 HP-UX 2 11-27-2009 04:16 AM
command does not return exit status due to tee anand_bh Shell Programming and Scripting 2 12-05-2008 11:20 AM
How to get exit code in a pipe-lined command? pankai Shell Programming and Scripting 3 01-10-2008 05:36 PM
Getting the exit status of a remote command zoonalex Shell Programming and Scripting 1 08-23-2006 04:58 PM



All times are GMT -4. The time now is 11:54 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?