为什么cURL请求会返回ZSH中每个请求的百分号(%)?

时间:2015-04-07 16:59:38

标签: curl command-line zsh

我注意到ZSH中任何cURL请求的返回都以%结尾,例如:

$ curl http://textbelt.com/text -d number="555555555" -d message="hey"
=> { "success": true }%

为什么要添加此字符,是否有标准的删除方法?

注意:ZSH是唯一一个我注意到这种情况发生的shell(在bash csh ksh sh tcsh zsh中测试)

2 个答案:

答案 0 :(得分:14)

这是一个zsh 功能,在命令完成后打印百分比和换行符如果该命令在其输出结尾处尚未包含换行符。如果zsh没有这样做,你要么没有注意到命令没有打印换行符这一事实 - 或者你看到zsh的命令提示符不是启动在边缘上,认为这是zsh中的一个错误。

像curl这样的工具会虔诚地打印从源头获得的任何结果,并且不应该在没有被要求的情况下自发地打印换行符。我经常用卷曲看到这种行为。如果您正在编写使用curl的工具,您当然可以选择自己添加换行符。

我建议不要添加新行,除非你真的需要。在你真的想要添加换行符的情况下,你可以使用一个单独的工具(例如echo) - 但最简单的卷曲是"写出"选项:

$ curl http://api.macvendors.com/0015c7   
Cisco Systems, Inc%     
$ curl -w '\n' http://api.macvendors.com/0015c7
Cisco Systems, Inc
$

来自curl的手册页:

   -w, --write-out <format>
          Make  curl  display  information  on stdout after a completed transfer. The format is a string that may contain plain text
          mixed with any number of variables. The format can be specified as a literal "string", or you can have curl read the  for-
          mat from a file with "@filename" and to tell curl to read the format from stdin you write "@-".

答案 1 :(得分:1)

尝试在邮件中明确添加换行符。

相关问题