我注意到ZSH中任何cURL请求的返回都以%
结尾,例如:
$ curl http://textbelt.com/text -d number="555555555" -d message="hey"
=> { "success": true }%
为什么要添加此字符,并且有标准的删除方法?
注意:ZSH是我注意到的唯一 shell (在bash csh ksh sh tcsh zsh中测试)
最佳答案
这是zsh的一项功能,如果该命令在其输出末尾尚未包含换行符,则该命令完成后会打印一个百分号和换行符。如果zsh没有这样做,则您可能永远不会注意到该命令未打印换行符的事实-否则您会看到zsh的命令提示符不在空白处开始,并认为这是zsh中的错误。
诸如curl之类的工具会认真地打印从源头获得的任何结果,并且在未经要求的情况下切勿自发打印换行符。我经常看到这种行为。如果要编写使用curl的工具,则当然可以选择自己添加换行符。
我建议不要添加换行符,除非您确实需要。如果您确实要添加换行符,则可以使用单独的工具(例如echo)-但是最容易使用curl的是“写出”选项:
$ 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 "@-".
关于curl - 为什么cURL请求在ZSH中的每个请求都返回百分号(%)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29497038/