* Naive read mistake
@ 2022-06-16 16:29 Perry Smith
0 siblings, 0 replies; only message in thread
From: Perry Smith @ 2022-06-16 16:29 UTC (permalink / raw)
To: Zsh-Users List
[-- Attachment #1: Type: text/plain, Size: 1089 bytes --]
I’ve been seriously confused with a simple function that is reading the output from a curl https command. I finally figured out the issue and everything is working as documented but thought I would tell of my saga.
From the documentation for “read”:
> The value (exit status) of read is 1 when an end-of-file is
> encountered, or when -c or -l is present and the command is not
> called from a compctl function, or as described for -q. Otherwise
> the value is 0.
I had the common loop:
while read line ; do … done
For me in this instance, the loop is not executed on the last line because it is not terminated with a newline. line is set but the read returns 1 since it hit EOF. All this is correct as far as I can tell but I just wasn’t expecting it.
I’m using curl with “-i” to an HTTPS API returning headers and JSON. The function I was having problems with was to separate the headers from the JSON output. So this issue might come up for others.
Thank you for your time,
[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-16 16:30 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-16 16:29 Naive read mistake Perry Smith
Code repositories for project(s) associated with this public inbox
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).