How to get exit status from a piped command in Linux shell

Posted by linuxaria on Feb 24, 2012 3:07 PM
By http://linuxaria.com
Mail this story
Web version

It’s funny how through small daily tasks sometimes it happen to find new features or commands that you do not knew not, and today this thing happened to me. In particular, I had to do something trivial on the shell of a server, run : command1 | tail-n 2 i use tail to keep, from a significant long output, only the last 2 lines which then i use in another function, but beyond this, I needed to understand if command1 was terminated with an exit code of 0 or if the code was not 0 which number it was.

Full Story

Printed at http://lxer.com/module/newswire/view/162873/index.html