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

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

问题描述

如果 curl 请求的 HTTP 响应正文不包含尾随换行符,我最终会遇到这种非常烦人的情况,其中 shell 提示位于行的中间,并且转义很混乱,以至于当我把屏幕上的最后一个 curl 命令,从该 curl 命令中删除字符会删除错误的字符.

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 deletes the wrong characters.

例如:

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

有没有什么技巧可以让我在 curl 响应的末尾自动添加换行符,让提示回到屏幕的左边缘?

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?

推荐答案

来自 man 文件:

为了更好地让脚本程序员了解开发进度curl,引入了 -w/--write-out 选项.使用它,您可以指定您想从上次传输中提取哪些信息.

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
' www.download.com

因此尝试将以下内容添加到您的 ~/.curlrc 文件中:

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

-w "
"

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

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