in reply to Detecting failed piped command run via ssh

Your Bash syntax for accessing all the elements of the PIPESTATUS array needs looking at. It should be:
${PIPESTATUS[@]}
With appropriate backslashing:
\$\{PIPESTATUS\[\@\]\}
You only get one element because using an array without an index gives the first element (in Bash and ksh).

Replies are listed 'Best First'.
Re^2: Detecting failed piped command run via ssh
by devnull (Initiate) on Apr 08, 2009 at 10:50 UTC
    Thanks, but I still get only one entry in @results.
    I figure I should get one entry as the contents of the .tar.bz2, and one as whatever is returned by  ;echo \$\{PIPESTATUS\[\@\]\}. Later code writes $results[0] to a file, which bunzip2 reports as corrupt, hence I figure that the backtick method is unable to separate the output of bzip2 -9 -c from  ;echo \$\{PIPESTATUS\[\@\]\}.
      When you say there is only one entry in @results, doea that one entry contain output from bzip2, or is it from PIPESTATUS? It could just be that bzip2 is not terminating the record with "\n", in which case inserting a dummy echo after the bzip2 should do the trick.