在curl响应正文结束时自动添加换行符 [英] Automatically add newline at end of curl response body

查看:4410
本文介绍了在curl响应正文结束时自动添加换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果curl请求的HTTP响应主体不包含尾随换行符,我会遇到这种非常恼人的情况,其中shell提示符位于行的中间,并且转义被弄乱了,当我放置



例如:

pre> [root @ localhost〜]#curl jsonip.com
{ip:10.10.10.10,about:/ about} [root @ localhost 〜]#

有一个技巧我可以用来自动添加换行符

解决方案

从man文件:


为了更好地让脚本程序员了解
curl的进度,引入了-w / - write-out选项。使用这个,你可以指定
来自你想要提取的上一个传输的信息。



显示与一些文本一起下载的字节数和
结束换行:

  curl -w我们下载了%{size_download} bytes\\\
'www.download.com


请尝试将以下内容添加到您的 〜/ .curlrc 档案:

  -w\\\


If the HTTP response body for a curl request doesn't contain a trailing newline, I end up with this really annoying condition where the shell prompt is in the middle of the line, and escaping is messed up enough that when I put the last curl command on the screen, deleting characters from that curl command delete the wrong characters.

For example:

[root@localhost ~]# curl jsonip.com
{"ip":"10.10.10.10","about":"/about"}[root@localhost ~]#

Is there a trick I can use to automatically add a newline at the end of a curl response, to get the prompt back on the left edge of the screen?

解决方案

From the man file:

To better allow script programmers to get to know about the progress of curl, the -w/--write-out option was introduced. Using this, you can specify what information from the previous transfer you want to extract.

To display the amount of bytes downloaded together with some text and an ending newline:

curl -w 'We downloaded %{size_download} bytes\n' www.download.com

So try adding the following to your ~/.curlrc file:

-w "\n"

这篇关于在curl响应正文结束时自动添加换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆