I've noticed that the return from any cURL request in ZSH ends in a %
, for example:
$ curl http://textbelt.com/text -d number="555555555" -d message="hey" => { "success": true }%
Why is this character being added and is there a standard method for removing it?
note: ZSH is the only shell that I notice this occurring (tested in bash csh ksh sh tcsh zsh)
'cURL' is a command-line tool that lets you transmit HTTP requests and receive responses from the command line or a shell script. It is available for Linux distributions, Mac OS X, and Windows. To use cURL to run your REST web API call, use the cURL command syntax to construct the command.
Similar to -L , --location , but enables you to send name and password to all redirections. Allow curl to follow any redirections. Specify the login options for email server authentication.
curl is a tool to transfer data from or to a server, using one of the supported protocols (HTTP, HTTPS, FTP, FTPS, GOPHER, DICT, TELNET, LDAP or FILE). The command is designed to work without user interaction.
This is a zsh feature that prints a percent-and-newline after a command completes if that command does not already include a newline at the end of its output. If zsh did not do this, you would either not ever notice the fact that the command didn't print a newline - or you'd see zsh's command prompt not start on the margin and think it was a bug in zsh.
Tools like curl religiously print whatever results they get from the source and should never spontaneously print a newline without being asked to. I see this behaviour most often with curl. If you are coding a tool that uses curl, you do of course have the option of adding in a newline yourself.
I suggest not adding a newline unless you really have to. In the case where you really want to add a newline, you can use a separate tool (echo for example) - but the easiest with curl is the "write-out" option:
$ curl http://api.macvendors.com/0015c7 Cisco Systems, Inc% $ curl -w '\n' http://api.macvendors.com/0015c7 Cisco Systems, Inc $
From curl's man page:
-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 "@-".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With