From: Perry Smith <firstname.lastname@example.org>
To: Zsh-Users List <email@example.com>
Subject: Naive read mistake
Date: Thu, 16 Jun 2022 11:29:17 -0500 [thread overview]
Message-ID: <8D7372B3-C4F1-4ED4-81D6-C11C3B7D385A@easesoftware.com> (raw)
[-- 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 --]
reply other threads:[~2022-06-16 16:30 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).