Shell-关于shell获得执行结果的问题?
我想获得curl -i ‘www.xxx.com’执行后的结果,并赋予变量,正常在命令行输出的结果是
HTTP/1.1 302 Moved Temporarily
Server: nginx/0.8.54
Date: Thu, 07 Jun 2012 06:11:13 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/5.3.6
Set-Cookie: PHPSESSID=d33ac5thh2b4c3r5fujp8gsia6; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
#!/bin/sh
tmpfile="/root/tmp1.txt"
curl -s -I "http://www.baidu.com" > ${tmpfile}
dos2unix -q ${tmpfile}
while read line
do
curl_result="${curl_result}${line}"
done < ${tmpfile}
echo ${curl_result}
查看man curl
PROGRESS METER
curl normally displays a progress meter during operations, indicating the amount of transferred data, transfer speeds and estimated time left, etc.curl displays this data to the terminal by default, so if you invoke curl to do an operation and it is about to write data to the terminal, it disables the progress meter as otherwise it would mess up the output mixing progress meter and response data.
很简单,你只需要使用-s选项(--silient)禁用PROGRESS METER就行了。
-s, --silent
Silent or quiet mode. Don't show progress meter or error messages. Makes Curl mute.
response=`curl -I "http://www.example.com/" -s`
json=$(curl -s http://www.test.com);
echo $json;