exit status of piped command line in ksh

In bash, from environment variable $PIPESTATUS we can retrieve exit staus of piped command line like below.

$ echo "some string" | grep x | tee some.tmp ; echo ${PIPESTATUS[1]}
1

However if I am on ksh I need to something like below to get exit status. I searched for it to get something like below.

$ getme=`((echo "some string" | grep x 3>&- 4>&- ; echo $? >&4) | tee some.tmp 1>&3 3>&- 4>&- ) 4>&1` ; echo $getme
1


$ getme=`((echo "some string " | grep me 3>&- 4>&- ; echo $? >&4) | tee some.tmp 1>&3 3>&- 4>&- ) 4>&1` ; echo $getme
0

Is there a simpler form to above one in ksh to retrieve exit status in piped command line?. And how to interprit above line. I do know little on subshell & usage of 4 as descriptor. Redirection part is little hart to interprit

Answers


$? does not suite ?

echo "some string" | grep x | tee some.tmp ; echo "Returncode: $?"

or you need specific error code for each pipe

you can also try using set options

-e

Unless contained in a || or && command, or the commandfollowing an if while or until command or in the pipeline following !, if a command has a non-zero exit status, execute the ERR trap, if set, and exit. This mode is disabled while reading profiles.

-o pipefail

A pipeline will not complete until all components of the pipeline have completed, and the return value will be the value of the last non-zero command to fail or zero if no command has failed.


Need Your Help

URL Redirects for SEO (in Flash)?

javascript ruby-on-rails flash seo

I am creating a flash site and am trying to make it SEO. I'm thinking a possible solution would be to render html to any search engine bot, or to anyone who needs accessibility, and rendering the ...