From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13372 invoked by alias); 2 Jun 2018 01:17:26 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 23425 Received: (qmail 12283 invoked by uid 1010); 2 Jun 2018 01:17:26 -0000 X-Qmail-Scanner-Diagnostics: from mail-lf0-f49.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.215.49):SA:0(-1.9/5.0):. Processed in 1.683888 secs); 02 Jun 2018 01:17:26 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_PASS,T_DKIMWL_WL_MED,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=XoIjxrvoy/nswg1cj6Rzbo83F+23bijLqQ/Fk93k6VQ=; b=hskVDAUvXLoQ1YXZi9IVMO6rXRPHGpIG5XfFx6M9xotsaMT+peANCilCZ/vBIJ7Uqv MC3+f2zJib2U+atVOHo+doB/K+yw/i099y7K+MtLU0j45DbS+PLfwkC+HOG5RKneD+KS alvBFrvyvNpuP1UVZbY7/Hy+EiLuaC19VzroSH9l+M49AOJ13oa3Axs1WXP4n2gEF0pZ NvTl5P0GGumz+GLg+3DfF+KD0WNHNRI/XDtlvvR9wQhF+BZ/XcryMIxv9pDT6RncR06l pKuPp1d48V4+hkpvfmVZE5fIEknNE6Iae6bYRXNBLsonPhyd6wi6J2KJUf9ZzF0ItWjf 5BJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=XoIjxrvoy/nswg1cj6Rzbo83F+23bijLqQ/Fk93k6VQ=; b=cufQNbrPlNRQfwkE6tbL5zT7kx4nFiiAbxKXR8995czH+IqNKcnOb2D6lYnr38pWKr /UbTLorPmeuAyqGD+VWA5+otmxZmGmGpymS/lYV0zGwLY6U1bs0JHEwJKxQjFGni1WXU SC9K8JhS1JateeS52N27TzkYB6tfNhJ2azc3mUYIugJu7RjsLs9vCKVvkNA4kU7/dSUf ZnH9zh6dh7jPZb6D+xDETG9bue+2DNNH2peNKydvg6O5IGKunglrqjzKQSSkYOfk/LLs +ri9UN2EgucusTqMEUskuFIsqxPZRjTXP30jR2XBL6SwqVPR49OuP79yEAr9a3FUXZ5L j48A== X-Gm-Message-State: ALKqPweHWsmmIf2ID10p4Sofj3h3Mr8MuqZN8rL7HPIpe8EM7H87/lpA RsnAblwcGAXBPqs7eLLIqSukP6hhx58zVYy7Ei+8L/n+ X-Google-Smtp-Source: ADUXVKK9ymaDbt9LA7a1cpRduKD+1pAzRK91SkA19q8O9lg/vlD0y9kzSNjpgQRYULDVtNf15A5tfYe2XY9ZCbZk/vc= X-Received: by 2002:a19:5011:: with SMTP id e17-v6mr5561693lfb.71.1527902240383; Fri, 01 Jun 2018 18:17:20 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20180601214714.GA11281@prometheus.u-strasbg.fr> References: <20180601214714.GA11281@prometheus.u-strasbg.fr> From: Bart Schaefer Date: Fri, 1 Jun 2018 18:17:19 -0700 Message-ID: Subject: Re: read options to slurp empty lines ? To: Marc Chantreux Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" On Fri, Jun 1, 2018 at 2:47 PM, Marc Chantreux wrote: > > i use to have slurp function made like this > > slurp () IFS=$'\n' read -r -d ' -A $1 I presume that to be a typo or cut-and-paste error because you have an unmatched single quote there. > i recently saw that > > print -l '' bar bang '' | slurp them > # got them=( bar bang ) > # expected them=( '' bar bang '' ) For the confused or those with proportional fonts, '' above is two single quotes, not a double quote, so there should be four lines output by "print -l". I get % typeset -p them typeset -a them=( bar bang '' ) The behavior of "read" is to collapse multiple consecutive occurrences of $IFS characters into a single one. Because an empty string followed by a newline looks like nothing more than a newline, all those lines collapse. [The single empty element I got at the end is there not because there were trailing empty lines, but because end of input was reached without finding the delimiter (this is not standard so probably ought to be controlled by POSIX_BUILTINS or something).] So for example: % print -l x '' '' '' bing bong '' '' '' y | slurp % typeset -p reply typeset -a reply=( x bing bong y '' ) Same thing happens in e.g. bash (except without the final empty element, see above). > i tried to patch it using some read options ... did i miss something using read builtin ? Only that there's no simple way to make it do what you want. :-) You're probably looking for this: slurp() { local REPLY IFS= read -d '' && set -A ${1:-reply} "${(@f)REPLY}" }