I’m trying this:
TIMEFORMAT=%R;
foo=$(time wget http://www.mysite.com)
echo $foo
and when I execute I see the number I want in the output but not in variable foo (echo $foo print nothing).
Why is that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You are not capturing anything in
foobecausetimesends its output onstderr. The trouble is that thewgetcommand also sends most of its output onstderr. To split the two streams (and throw away the output fromwget) you will need to use a subshell:Here is an explanation of what’s going on…
The inner part of this command:
Sends both
stderrandstdoutto/dev/null, essentially throwing them away.The outer part:
Sends
stderrfrom thetimecommand to the same place thatstdoutis sent so that it may be captured by the command substitution ($()).Update:
If you wanted to get really clever, you can have the output of
wgetpassed through tostderrby juggling the file descriptors like this: