Chen Li Yong
Chen Li Yong

Reputation: 6107

How to use curl -w switch with multiple data token as format parameter?

I want to get two things from curl: http_code and time_total from a single curl request. How should I formulate the -w %{insert_formatting_here} ?

These works:

result = $(curl -s -w %{http_code} -o temp.txt) "http://127.0.0.1" 
echo "$result"
result = $(curl -s -w %{time_total} -o temp.txt) "http://127.0.0.1" 
echo "$result"

Result:

200
0.004

But this didn't work as I expected:

result = $(curl -s -w %{http_code time_total} -o temp.txt) "http://127.0.0.1" 
echo "$result"

Result:

<p>where "$CATALINA_HOME" is the root of the Tomcat installation directory. If you're seeing this page, and you don't think you should be, then you're either a user who has arrived at new installation of Tomcat, or you're an administrator who hasn't got his/her setup quite right. Providing the latter is the case, please refer to the <a href="/docs">Tomcat Documentation</a> for more detailed setup and administration in %{http_codeReserved99-2014 Apache Software Foundation<br/>ht="80" alt="Powered by Tomcat"/><br/>s working on Tomcat</li>configuring and using Tomcat</li> developing web applications.</p>

I cannot find any tutorial that helps me to put multiple token on the format parameter. They only list the format token, but there's no example or anything so far.

Upvotes: 0

Views: 458

Answers (1)

Tom M.
Tom M.

Reputation: 136

Each placeholder needs to be in brackets, i.e.:

curl -s -w "%{http_code}:%{time_total}" http://127.0.0.1

Upvotes: 1

Related Questions