Quote:
Originally Posted by bcnx
Do you think there is any way to capture this in a variable without redirecting to a file?
|
Yeah, though it starts to get a bit messy, so you are perhaps better off having a temporary file than following something like this example:
Code:
ERROR=$( { echo "abc" | ssh host2 "cat -B" ; } 2>&1 | tail -1 )
This takes the pipeline in the braces, redirects all of its stdout and stderr together through
tail to strip off all but the last line, and assigns it to
$ERROR. You can throw away the
stdout inside the braces by redirecting to
/dev/null if you wanted. The semicolon is required.