This script was posted as answer to a Question. And I'm trying to work out what's going on.
result=$(
{
{
ssh host app-status >&3 3>&-; echo "$?"
} | {
until read -t1 ret; do
printf . >&2
done
exit "$ret"
}
} 3>&1
)
Here's my explanation, but I'm sure it's wrong.
- The outer
{...} 3>&1
: fd 3 is opened as a duplicate of stdout - Then second half of pipe, '| { }` no redirection
- In read loop printf's stdout is duplicated with stderr, so in 2. (above) all output actually comes via stderr.
- Now the first half of pipe,
{ ssh ... } |
: stdout of ssh is dupped onto fd3 (which is in fact stdout from 1. fd 3 is closed with3>&-
so stdout is re-opened onto what it was originally and this is piped into 2. - finally,
echo
just prints to stdout
So my question (problem with understanding) is; Is the result of this the same as just printf to stderr ? What does the voodo redirect to 3 actually achieve? Is there anything asynchronous in here ?
exit: : numeric argument required
orread: read error: 0: Permission denied
followed by an infinite series of dots, depending on how app-status behaves on the remote side.