From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HTML_MESSAGE,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 15970 invoked from network); 12 Jan 2024 20:03:58 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 12 Jan 2024 20:03:58 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1705089838; b=EQ3nc3uZ+mXcVI3PD0lYMHUGNfV8RAhsNR5VAr3OBcPVG0FVS9MkZW8qpvtFrLMlluS95tduUk fx6J1thRku368pj43UQ8g8iLnIGE+wWDi4b8h+ipreVb7XMkhtrwqaHAUburo7j6aKhFtxe8e0 D86Y7ZThrym8h+Zj/nD0MDio/hkX9kSla98348arXQ2KrU3LXb3QVh/ncOqk6gaxn04skm8UN6 5L/Zx+scKSypDKLLw1qLLR6Vv5TPuc6JYE6d1v5VWh54kDTNtIG5kAKgJi2HMQP18f8ph8NrnW nKaMlPUlYpsONvxxmA+O1KAVVneJ9f6AOpTR125AkKgu5g==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f43.google.com) smtp.remote-ip=209.85.218.43; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1705089838; bh=QqT2ZcLcbi0b0jxQkTglKNfiEmKHjRMow+fKFFv+iAw=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=gHy6R7iXWjb6+zch6Km8hHaeae3jcx2q8esDkHW5zQ683g+HaqG7dhtlCLzg/cX785ILXdw79Z N7MdPq2VAG27e2pwA5Ae1pjeOFBIsPZSDfQSsE+r158Zb/5BnsnX/F1BXxUvb7uYyXhDcuJLGs ExRvYxLJP354upiKZwgjuG94nEBdOGL9Fna3kSuHhGLe5MwJYwsiPyQC5aE1C2hNI8QZKALnNV ch4GhHIpFuk3piuZ/tL9nmbu669gdGth98zJAJ3XuB+3elYA+abgSEobBLCloWM4HfEbmtUx6C Ff1Pt33rVk4rtmkZKBfVD65hq9Yyp+cIDT1Z4xTKrZWP5w==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:To:Subject:Message-ID: Date:From:In-Reply-To:References:MIME-Version:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=0v2zgDCJB9meDCo0V06jL3tVzbtUPo7VZiAppuBYCRk=; b=mPKqbCL2dYwD3a0ctDTMZu6yhB Uu9EhKqSZ5DYuBJ02pnJTOtPWcKu0lkyic9fngF1rMhw92JLyhgC+9FOFpkcQxSlLaidVSz4MEWek qJ05UELmTkCeWnw7ynEYAiTiEiU0yGKwUtn7xxeyTDDrg4F/p+MOHd28eqzszhJ4Mo04dMf4DZQzk Ivgo8I0Ea4HBZFvxM2HI5CFbxV4cZo8aqg3DsRbj4p4QKHMFxdYI5tyzjl4PGYFIXmDyHo/3nPR0W 0qTrS9QiFir4eJfrBI/pQiWKboWeddW1zsnE+tiDvcLLK6V4r9s8W6i6DwfQ7O0SveDt+7eBIs74N cYQUv18g==; Received: by zero.zsh.org with local id 1rONkz-000E5G-Uy; Fri, 12 Jan 2024 20:03:58 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f43.google.com) smtp.remote-ip=209.85.218.43; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ej1-f43.google.com ([209.85.218.43]:60700) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rONkM-000DM6-GO; Fri, 12 Jan 2024 20:03:19 +0000 Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a298accc440so851512166b.1 for ; Fri, 12 Jan 2024 12:03:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20230601.gappssmtp.com; s=20230601; t=1705089798; x=1705694598; darn=zsh.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=0v2zgDCJB9meDCo0V06jL3tVzbtUPo7VZiAppuBYCRk=; b=H85u61W8YS3RF2LVnNvdcGIh3mzWEOUC80iWTH7+Krva7m3E+S213ZMLmuhSBYjbXA FKur1XsNtyrNRDuNP7Q55vVaFgx0JYfSBMwQ6qdk8EJZ4im4eKv78MemajqB3k5Q6VTW pnws3vz5o3KcI2WRnxEqgiPMnWOGfWg05jzDn3Na5xF1/dtn9DGmRG79/sr/IPW9PMnN HdJ0NucFhfiAYlEkEbIwDMtMHk0pt60mDblxYPazIzD7JgXLZqv9OaivyjotbrFP1iO1 AVq0t8+2tUDB0wD/u2vhjiKnL6/KGOt3ILLWUbzheXbRkwxE7vNneyLc6RL2QbldeIau LKWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705089798; x=1705694598; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0v2zgDCJB9meDCo0V06jL3tVzbtUPo7VZiAppuBYCRk=; b=MGtrcALW26D2SrQm1Z1vNKfR/QCq0hdWXkxlwlYNHN2Pb+bYmPKj3KIbq1Opo3Aoh3 fO8jcafDtmrE1sSqX2ptz7ufbJq71vCWt5rXCaSQ6Sn9nQSF6uY/V66VsKi+XMdW7F1A nQXgH4Yn3Qx7Mbbc77/BAS0ER42U+3dTpH0co/dhGvNvPIp4qDdpaeA0LrUcXmvyTnPW 8EfHwhnQG8NmC+0IOKDMaosUZDvp/6U4YWquZ6Z/s76scJosEsVM+nH2prGgRrgkdR6k UYejyJaojxGKAMbfNNnkTjhAd2T64ApxkCNWyDQIg1HwqeB0+mlydEAVFTKvCqxoGwHw O+tg== X-Gm-Message-State: AOJu0YxKvKI1vDxXm9roTaduYxyMeXRBOjQRssXrghI/NNxCscaArpM5 weqasyEDgDtdvtCliP/4v3en+0MJyNPVKsobiR4LkGvCnUQBYmUc/UDuqdc= X-Google-Smtp-Source: AGHT+IFYVyuOeZ8BykYYYBxxvz1fxf7uXL5nuJwO58LxZAvY0OqeBmgBGPYcF9okOf/ykk/eGfIuOfNxLMMeO3CI6mY= X-Received: by 2002:a17:906:9c94:b0:a2d:dde:9ff0 with SMTP id fj20-20020a1709069c9400b00a2d0dde9ff0mr150911ejc.23.1705089797979; Fri, 12 Jan 2024 12:03:17 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Bart Schaefer Date: Fri, 12 Jan 2024 12:03:07 -0800 Message-ID: Subject: Fwd: more splitting travails To: Zsh Users Content-Type: multipart/alternative; boundary="000000000000b80db8060ec527e3" X-Seq: 29449 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: --000000000000b80db8060ec527e3 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable This was sent privately to me but pretty obviously intended for the list. ---------- Forwarded message --------- From: Mark J. Reed Date: Fri, Jan 12, 2024, 11:54 AM Subject: Re: more splitting travails To: Bart Schaefer We talked offlist about how zsh inherited the paradoxical-looking and "${array[@]}" from earlier shells, though it works differently such that a simple $array usually does what you want? Well, here's where the exception to that "usually" comes in. Although the elements of an array expanded as simply $array don't get generally re-split on whitespace the way an unquoted ${array[@]} or ${array[*]} does in bash, any elements that are completely empty do get lost: *zsh% *array=3D(one two '' '' five ) *zsh% *echo $#array 5 *zsh%* printf '%s\n' $array # King Arthur, is that you? one two five *zsh% * So that's where you need the wonky inherited syntax if you want to include empty values: *zsh%* printf '%s\n' "${array[@]}" one two five *zsh%* Bart's question is also salient, however: > I have a file with blank lines in it, I read it into a variable How do you read it in, and into what kind of variable? If you want to read a file into an array of lines, preserving empty lines, you can do this: lines=3D("${(@f)$(<~"$filename")}") The stuff in parentheses just inside the ${ are parameter expansion flags, which you can read about on the zshexpn man page. In particular, the f flag splits the value on newlines, while the @ flag does the same thing as "${array[@]}" (which could therefore also be written as "${(@)array}"), but also works in other kinds of expansions, such as $( wrote: > On Fri, Jan 12, 2024 at 11:05=E2=80=AFAM Ray Andrews > wrote: > > > > There's nothing harder than really getting on top of splitting issues := ( > > > > I have a file with blank lines in it, I read it into a variable > > This is probably the place you're getting messed up. HOW do you read > it into a variable? > > > Other various attempts give me the number of elements being the > > character count. Weirdly there's places where I iterate over all the > > lines in 'List' and it *counts* nine, but only displays five. > > Here you've probably done an earlier step right, but are forgetting to > quote what you're passing to print (or whatever "display" means). The > default for arrays on the command line is to remove empty elements > unless quoted. > > --=20 Mark J. Reed --000000000000b80db8060ec527e3 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
This was sent privately to me but pretty obviously intend= ed for the list.

---------- Forwarded message ---------
From: Mark J. Reed <markjreed@gmail.com>
Date: Fri, Jan 12, 2024, 11:54 AM
Subject: Re: more splitting t= ravails
To: Bart Schaefer <schaefer@brasslantern.com>


We t= alked offlist=C2=A0about how zsh inherited the paradoxical-looking and=C2= =A0"${array[@]}" from earlier she= lls,=C2=A0 though it works differently such that a simple $array usually does what you want?=C2=A0

= Well, here's where=C2=A0the exception to that "usually" comes= in.

Although the elements of an array expanded as simpl= y $array don't get generally re-split o= n whitespace the way an unquoted ${array[@]} or ${array[*]} does in bash, any elements= that are completely empty do get lost:

=C2=A0 =C2=A0 = =C2=A0 =C2=A0=C2=A0zsh% array=3D(one two &#= 39;' '' five )
=C2=A0= =C2=A0 zsh% echo $#array
= =C2=A0 =C2=A0 5
=C2=A0 =C2=A0 = zsh% printf '%s\n' $array # King Arthur, is that you?
=C2=A0 =C2=A0 one
=C2=A0 =C2=A0 two
=C2=A0 =C2=A0 five
=C2=A0 =C2= =A0 zsh%=C2=A0

=
So that's where you need th= e wonky inherited syntax if you want to include empty values:
<= div>
=C2=A0 =C2=A0 zsh% printf '%s\n' "${array[@]}"
=C2=A0 =C2=A0 one
= =C2=A0 =C2=A0 two
=C2=A0 =C2=A0=C2=A0
=C2= =A0 =C2=A0=C2=A0
=C2=A0 =C2=A0 fi= ve
=C2=A0 =C2=A0 zsh%

Bart's question is also salient, however:

=C2=A0 =C2=A0=C2=A0> I have a file with blank lines in it, I read it into a variable

How do you r= ead it in, and into what kind of variable?=C2=A0If you want to read a file = into an array of lines, preserving empty lines, you can do this:
=
=C2=A0 =C2=A0 lines=3D("${(@f)$(<~"$filename")}")

=C2=A0The stuff in parentheses just inside the ${ are p= arameter expansion flags, which you can read about on the zshexpn man page.= =C2=A0 In particular, the f flag splits the= value on newlines, while the=C2=A0@ flag d= oes the same thing as "${array[@]}"=C2= =A0(which could therefore also be written as "${(@)array}"), = but also works in other kinds of expansions, such as=C2=A0$(<filename) used here (which means=C2=A0 &q= uot;get the contents of the file").

On Fri, Jan 12, 2= 024 at 2:19=E2=80=AFPM Bart Schaefer <schaefer@brasslantern.com> wrote:
On= Fri, Jan 12, 2024 at 11:05=E2=80=AFAM Ray Andrews <rayandrews@eastl= ink.ca> wrote:
>
> There's nothing harder than really getting on top of splitting iss= ues :(
>
> I have a file with blank lines in it, I read it into a variable

This is probably the place you're getting messed up.=C2=A0 HOW do you r= ead
it into a variable?

> Other various attempts give me the number of elements being the
> character count.=C2=A0 Weirdly there's places where I iterate over= all the
> lines in 'List' and it *counts* nine, but only displays five.<= br>
Here you've probably done an earlier step right, but are forgetting to<= br> quote what you're passing to print (or whatever "display" mea= ns).=C2=A0 The
default for arrays on the command line is to remove empty elements
unless quoted.



--
Ma= rk J. Reed <markjreed@gmail.com>
--000000000000b80db8060ec527e3--