![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's | manas6 | UNIX for Dummies Questions & Answers | 0 | 06-05-2008 03:44 AM |
| Useful piped filter combinations? | Nelledawg | UNIX for Dummies Questions & Answers | 3 | 11-02-2007 01:28 PM |
| return code of a unix command | ramky79 | Shell Programming and Scripting | 1 | 08-02-2007 12:34 PM |
| Mailx Return Email Command | lisa0703 | Shell Programming and Scripting | 1 | 01-23-2007 05:38 PM |
| perl... how to tell if a piped command is still running? | boytheo | Shell Programming and Scripting | 0 | 08-17-2005 08:01 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Return value of piped command?
Code:
grep $SEARCH_STRING /etc/passwd | cut -d":" -f 1,5 How can I get the success status of grep alone? |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Different shells have different mechanisms for dealing with this situation.
Bash 3.0+ and ksh93 have the pipefail option (set -o pipefail) which changes the exit code behavior of pipelines and reports the exit code of the pipeline as the exit code of the last program to return a non-zero exit code. Bash has the PIPESTATUS array variable which contains a list of exit status values from the processes in the most-recently-executed foreground pipeline zsh has pipestatus. Another way is to use coprocesses. |
|
#3
|
|||
|
|||
|
I'm using ksh and the command set -o pipefail fails with the message
Code:
ksh: pipefail: bad option(s) |
|
#4
|
|||
|
|||
|
Quote:
|
|
#5
|
|||
|
|||
|
You to combine exit statuses logically, so that you can test more than one thing at a time.
Code:
statement1 && statement2 Code:
statement1 || statement2 Regards |
|
#6
|
|||
|
|||
|
But you can't do that in a pipeline.
Another makeshift solution would be to invoke a subshell and have it somehow smuggle out the exit status to a dedicated file descriptor. I don't think we want to go there, though. |
|||
| Google The UNIX and Linux Forums |