为什么这个bash命令不会回显到一个variables中,我该怎么做才能改进?

我有一个我正在努力改进的bash脚本 ,并且由于丹尼斯·威廉姆森 ( Dennis Williamson)的帮助 ,已经提供了一个很好的解决scheme。 不幸的是,其中一条线不再回应我可以操作的variables,而是直接转储输出。 如果我解决这个问题,我会很高兴。

为什么这个bash命令不会回显到$ resultvariables中,我能做些什么来改进?

result=$( time wget -q --output-document=/tmp/wget.$$.html http://domain.tomonitor.com 2>&1; ); 

编辑:我试过的各种解决scheme

  result=$( { time (/usr/local/bin/wget -q --output-document=/tmp/wget.$$.html --header="Host: blogs.forbes.com" http://$host) } &2>1 ); result=$( { time (/usr/local/bin/wget -q --output-document=/tmp/wget.$$.html --header="Host: blogs.forbes.com" http://$host) } ); result=$( ( time (/usr/local/bin/wget -q --output-document=/tmp/wget.$$.html --header="Host: blogs.forbes.com" http://$host) ) ); 

EDIT2:

我正在回应这样一行:

  echo "$date, $host, $result" 

date和主机当前正常。 $结果不是。

我得到这样的线:

3.887

星期二2月15日08:39:53 PST 2011,192.168.0.2,

3.910

星期二2月15日08:39:57 PST 2011,192.168.0.3,

我期待这样的线路:

星期二2月15日08:39:53 PST 2011,192.168.0.2,3.887

2月15日星期二08:39:57 PST 2011,192.168.0.3,3.910

在命令replace中,但在redirect之前,您需要使用花括号:

 result=$( { time wget -q --output-document=/tmp/wget.$$.html http://domain.tomonitor.com; } 2>&1; ); 

这捕获了time的输出。 如果你想捕获wget的错误输出(你已经把它的常规输出保存到一个文件中),你需要做一些不同的事情,这取决于你想要做什么。 它可能涉及额外的文件描述符,或者简单地使用我在我的回答中显示的redirect(而不是使用--output-document )。

我认为这应该去堆栈溢出,但你试过吗?

 result=$( time (wget -q --output-document=/tmp/wget.$$.html http://domain.tomonitor.com 2>&1;) );