Bash: Find out the exit codes of all piped commands

Posted over 7 years ago. Visible to the public. Linked content.

Bash stores the exitcodestatus of piped commands in the environment variable PIPESTATUS

So you can just echo ${PIPESTATUS[@]} to get them all.

13:52:30 ✔ claus:~$ ps ax | grep /usr/bin/ruby
13205 pts/20   S+     0:00 grep --color=auto /usr/bin/ruby


13:52:43 ✔ claus:~$ echo ${PIPESTATUS[@]}
0 0

PIPESTATUS is an array, so you can get the exitcode of an specific command (first pipe):

13:54:20 ✔ claus:~$ echo ${PIPESTATUS[1]}
0
Avatar
Claus-Theodor Riegg
Last edit
Over 7 years ago
Claus-Theodor Riegg
Keywords
ops
About this deck
We are makandra and do test-driven, agile Ruby on Rails software development.