0

The result of curl -s http://127.0.0.1 is 200 OK

The result of /usr/bin/time -f "%e" curl -s http://127.0.0.1 is 200 OK0.08

In this case, I only need 0.08. How can I only get 0.08 instead of the whole string when I redirect the output to >> result.txt?

ps: the response can change in the future (not always 200 OK), and the format of time can also change in the future. So I really need a solution that is not based on string manipulation. Thanks.

tripleee
  • 175,061
  • 34
  • 275
  • 318
Chen Li Yong
  • 5,459
  • 8
  • 58
  • 124
  • Are you sure your `/usr/bin/time` writes to stdout? You're saying if you do `/usr/bin/time ls > /dev/null` it doesn't print anything at all? I would have expected it to write to stderr. – John Zwinck Dec 08 '15 at 09:18
  • Possible duplicate of [bash redirect stderr for time command?](http://stackoverflow.com/questions/29322479/bash-redirect-stderr-for-time-command) – tripleee Dec 08 '15 at 09:20

1 Answers1

1

Do this:

/usr/bin/time -f "%e" curl -s -o /dev/null http://127.0.0.1

By adding -o /dev/null you are telling curl to write its output nowhere, leaving you with only the output of time.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436