The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to get the exit status yhacks Shell Programming and Scripting 1 05-19-2008 08:06 AM
exit status conditions sdcoms UNIX for Dummies Questions & Answers 6 05-16-2007 10:40 AM
exit status moxxx68 Shell Programming and Scripting 1 12-04-2004 07:27 PM
tar exit status thorndike UNIX for Dummies Questions & Answers 3 01-22-2002 04:39 PM
ftp exit status. oracle8 UNIX for Advanced & Expert Users 1 10-21-2001 11:34 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-28-2005
diganta diganta is offline
Registered User
  
 

Join Date: Dec 2004
Location: India, Bangalore
Posts: 18
Problem with exit status

Hi,

Consider the output of the following commands:

case1)
-------
# ifconfig -a | grep "UP" | grep uplink0:1
# echo $?

Output is: 0

case2
------
# ifconfig -a | grep "UP" | grep uplink0:1; echo $?

Output is: 1

In case2 we got the exit code as 1, which is the actual exit code.
Why did we not get the actual exit code in case1?

What is the difference between executing two different command at the same time (as in case 2) and one after the other (as in case 1)? In both the cases the commands will get executed in the same sequence.

Any help will be highly appreciated.

Thanks.
  #2 (permalink)  
Old 09-28-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Before starting off, you should know that the exit status that is printed is the exit status of the last command in the pipeline; i.e. the exit status of grep 'uplink0:1' is the one that is printed.

man grep says
Code:
       Normally, exit status is 0 if selected lines are found and 1 otherwise.
       But the exit status is 2 if an error occurred, unless the -q or --quiet
       or --silent option is used and a selected line is found.
So in your case, grep did find a favorable result and threw the exit status of 0. In the second case, grep threw up nothing. Hence an exit status of 1.

In case you do want to find out the exit status of the commands in the pipeline, look at this post - Pipelining.

vino
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:21 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0