![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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. |
|
|||||
|
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.
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 | ||
|
|