Hey, grail, your
BashFAQ/024 is great, but lacks one useful method: using a temporary descriptor to pass the result values. This works in all POSIX shells, like bash and dash, it might even work in Bourne shell.
Code:
exec 3>&1
result=`some-command some-parameters ... >&3 ; echo new-result`
exec 3>&-
For longer stuff and multiple variables, this can be extended to
Code:
exec 3>&1
result=(`exec 4>&1 1>&3
# do some bash stuff, stdout and stderr work normally
echo newval1 newval2 newval3 >&4
`)
exec 3>&-
val1="${result[0]}"
val2="${result[1]}"
val3="${result[2]}"
No descriptors are left open; this is quite clean. Although
$(...) would nest much better, older shells may only support
`...` so I used the latter just in case here.
Nominal Animal