exit status of command in a pipe line

Tags
beginners

 

 
Thread Tools Search this Thread
# 1  
Old 02-12-2004
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 12:29 PM..
# 2  
Old 02-12-2004
unfortunetly not that i have found.

i also hit that wall when i do certin stuff.
# 3  
Old 02-12-2004
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
something says i shouldnt have skipped that section on file handles.
# 5  
Old 02-04-2006
As usual, very ingenious solution Perderabo.

Would there be any way possible to utilize xargs to facilitate this same requirement?
# 6  
Old 02-04-2006
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

# 7  
Old 02-04-2006
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;

 

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Similar Threads More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help with finding the exit status of a 'nohup' command using 'PID'. SriRamKrish Shell Programming and Scripting 4 09-18-2014 11:54 AM
Exit Status of Command pvmanikandan Shell Programming and Scripting 1 12-26-2013 01:25 PM
Exit Status Of Find Command Ariean UNIX for Dummies Questions & Answers 6 06-04-2013 09:17 PM
Check the exit status in a pipe call Rkolbe Shell Programming and Scripting 7 10-05-2011 05:39 PM
Unable to find exit status of piped command proactiveaditya Shell Programming and Scripting 12 09-27-2011 08:06 AM
Equivalents of tee command to find exit status of command vibhor_agarwali UNIX for Advanced & Expert Users 7 06-03-2011 02:16 AM
Logins command exit status is 236 not 0 parkea2 HP-UX 2 11-27-2009 05:16 AM
command does not return exit status due to tee anand_bh Shell Programming and Scripting 2 12-05-2008 12:20 PM
Move Command and exit status problem visingha Shell Programming and Scripting 10 09-13-2008 09:08 PM
Move Command and exit status problem visingha UNIX for Dummies Questions & Answers 1 09-12-2008 03:14 AM
How to get exit code in a pipe-lined command? pankai Shell Programming and Scripting 3 01-10-2008 06:36 PM
Getting the exit status of a remote command zoonalex Shell Programming and Scripting 1 08-23-2006 05:58 PM
how to find the exit status for the last executed command vijay.amirthraj UNIX for Dummies Questions & Answers 1 07-04-2006 11:14 PM
Incorrect Exit Status Returned from FTP command - Help?? frustrated1 Shell Programming and Scripting 3 08-22-2003 04:25 AM
How to find the exit status of last command in Unix? rajugp1 Programming 1 09-10-2002 12:52 PM
All times are GMT -4. The time now is 02:58 AM.

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





Not a Forum Member?
Forgot Password?