Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Naive read mistake



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,
Perry

Attachment: signature.asc
Description: Message signed with OpenPGP



Messages sorted by: Reverse Date, Date, Thread, Author