Skip to content

Internal Bash Variable – PIPESTATUS

If you aren’t aware, there are a lot of useful internal BASH variables, some of which can be found here:

https://www.tldp.org/LDP/abs/html/internalvariables.html

One of particular use is PIPESTATUS. This can be very useful if you need to pipe a commands output to another command, and you need to check the return code.

For instance:

my_super_command | tee my.log

If my_super_command fails and you print the last return code you will see everything worked just fine:

echo $?

However, if you print the PIPESTATUS[0], then you can see the error:

echo $PIPESTATUS[0]

Categories

Linux

TheSoftwareProgrammer View All

I like science and writing software.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: