We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

understanding $PIPESTATUS

( make 2>&1 | tee make.log && exit $PIPESTATUS ) &&

Could someone give me a detailed explanation of the above line? I know that tee is creating a text file while also allawing the output to come to the screen but need a better understanding of $PIPESTATUS. Is "exit" exiting everything to the left of it or $PIPESTATUS to the right? Why are there two sets of "&&"? And I'M sure the variable $? comes it to play somewhere here. Thanks.

2
Contributors
1
Reply
56 Minutes
Discussion Span
6 Months Ago
Last Updated
2
Views
Question
Answered
Garrett85
Posting Pro in Training
426 posts since Oct 2009
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

$PIPESTATUS is an environment variable that holds the return values from any single, or chained commands in an array.... The page here should explain it far better than I can!:
http://www.linuxnix.com/2011/03/pipestatus-internal-variable.html

The && is a logical/boolean AND, similar to C, C++, Java etc.
As far as I understand it, the && inside the braces is part of the compound, boolean expression based on the commands contained in the braces. The && at the end of the line means that the next command (or line) in the bash script will only be executed if the commands to the left of the && (so basically if everything inside the braces) succeeds. So the next line or command in the shell script is the right hand part of the AND at the end of the code you've posted.

So it's kinda like:
If (make 2>&1 OR tee make.log AND exit $PIPESTATUS) AND NextLineOrCommand.....

So it's just a way of conditionally chaining several commands together.
At least I think that's the way it works!

JasonHippy
Practically a Posting Shark
862 posts since Jan 2009
Reputation Points: 615
Solved Threads: 146
Skill Endorsements: 5
Question Answered as of 6 Months Ago by JasonHippy

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0630 seconds using 2.81MB