curl在管道传输到head命令时给出错误

curl在管道传输到head命令时给出错误,curl,stream,pipe,head,Curl,Stream,Pipe,Head,这非常有效,没有错误: $ curl -sSL https://coinbase.com/api/v1/prices/historical 2014-04-27T18:19:17-07:00,430.52 2014-04-27T18:10:24-07:00,436.25 2014-04-27T17:56:57-07:00,436.14 ... 这会产生以下错误: $ curl -sSL https://coinbase.com/api/v1/prices/historical | head -

这非常有效,没有错误:

$ curl -sSL https://coinbase.com/api/v1/prices/historical
2014-04-27T18:19:17-07:00,430.52
2014-04-27T18:10:24-07:00,436.25
2014-04-27T17:56:57-07:00,436.14
...
这会产生以下错误:

$ curl -sSL https://coinbase.com/api/v1/prices/historical | head -n 1
2014-04-27T18:19:17-07:00,430.52
curl: (23) Failed writing body (0 != 186)
当我向
grep
tail
发送管道时,它不会失败,但当我向
head
发送管道时它会失败(即使没有参数)

我得到了我想要的,但它给了我一个错误。最后一个数字(上例中为186)每次都会改变。我又运行了三次,得到了1650、3988和923

我试着用
-B
选项运行它。如果有用的话,我使用OSX 10.9。我没有
~/.curlrc
。下面是
curl--version
的输出:

curl 7.30.0 (x86_64-apple-darwin13.0) libcurl/7.30.0 SecureTransport zlib/1.2.5
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smtp smtps telnet tftp
Features: AsynchDNS GSS-Negotiate IPv6 Largefile NTLM NTLM_WB SSL libz

这里出了什么问题?

head
curl
写入之前关闭管道。您可以使用-N标志禁用curl中的缓冲,从而将所有输出写入一个大数据块中的管道,以便
head
能够对整个响应进行操作:

curl -sNL https://coinbase.com/api/v1/prices/historical | head -n 1

谢谢你回答我两年前的问题!