I don't know
ash at all. This general workaround should work even in
: > "$psf" # to make the file empty
( dd if=/my/block/device; echo "1 $?" >> "$psf" ) \
| ( ssh myuser@otherserver "gzip > file.gz"; echo "2 $?" >> "$psf" )
Then you check the content of
/tmp/pipestatus. There is a flaw: race condition, the two
( ) blocks run in parallel, they may output to the file not in the right order. I used
>> so neither message will overwrite the other; the "messages" are short, so they shouldn't get interleaved; i numbered the "messages", so even if they are not in order, you can retrieve the right order later (
The above code is just an example anyway. More robust solution uses
mktemp to create a temporary file(s),
printf instead of
echo. To get rid of race condition entirely, you need to write to separate files:
# you may want to check if the above command succeeded
( dd if=/my/block/device; printf '%s\n' "$?" > "$psd/f1" ) \
| ( ssh myuser@otherserver "gzip > file.gz"; printf '%s\n' "$?" > "$psd/f2" )
# retrieve the results here, they are in "$psd/f1" and "$psd/f2"
rm -rf "$psd"
It's not as good as Bash's
PIPESTATUS because it relies on some filesystem and ability to write there, few things can go wrong and may not be caught. Still better than nothing.