From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 920DB20CE7 for ; Sat, 13 Apr 2024 17:14:51 +0200 (CEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1713021291; b=Un5OFPnCdKOeKnqO+TgzCGG0lubYNchLY2VzTa6Qg6deM7Wr1XNIy6zqpUszDZB0sYjnqfbncl HUbIMUvxqPgYP/MC2EDaFntSCLtfkHjhua2jiIJOGXWMG1i24OfZJnGKZMYVkwVJGDgv182Y3n lT14cZeOj9Hni7Jd6hl4XlVYuEA8N+YNGAL8nzJoSvt5A9IZv7qQVGIX7Uez1ByUn0qmwfJ8+Q wgaWtGDO4dpUQfOn34I7vjnD4VHdGuZ/G2Y/Uw6pPPMzR4GzAoUmZm22XTxj4rg3wvE8Iy3Taj 5OmW78+s8xnqNAJHnrFKRWCjY8mbjMDnm1qX79E6uu0/9A==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mta04.eastlink.ca) smtp.remote-ip=24.224.136.10; dmarc=none header.from=eastlink.ca; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1713021291; bh=B+NICpz3C0BRt2NfQoBJs0/w3Ji1EuR1My57AxQ0YkI=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:From:References:To:Subject:MIME-Version:Date: Message-ID:Content-Type:DKIM-Signature; b=j+Pz2lh55cVl+matqYuzTFqRUABc+43JMM5jdJBVTDOjaN4cXa8/8qT+IMRJHMnKg7uE9yqTNr fvL+d5909GdDHm7nhOyMr8QGI0Ry0kpzxfYJVE2O0gc8hJWSQaHGc1h/KWOab2sk/csNSNn+aS q53U+F2XXF43pprgHC3zgQhLvbLHyi6pkKnkXcNJgUm8OfNxARu6xLs3b3SXNuQ86eqOf+hX6w 7wS7uO/ZWKqVaooF2qMR8hoL2cAHZZKUTnBCid5EpikMBrB9stn2LUSMNlVcfLxIzaNN0dbGvM ZA1i66pYUxY4bzrtm+8v3iARmtVtTRFi84ObA/R0JNPn4Q==; 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:In-reply-to:From:References:To: Subject:MIME-version:Date:Message-id:Content-type:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=7D8nEgGzA7QXPD5+zm2KmgopX9kuLEN9SHKNl/Lpbrc=; b=nNQ6EHtFM0UsvomHpoxkekVeIq wlLTsw7ExMgq/Wp23jngNfINxYdX5e1QTb9OHOBvy9GZEY935Li/n/OHmugFZvkfklG35+Cgq67D0 tx1YN4xxOCJnwQfvhJFbEi8ypn9Yi++oOeG8Y8hndG/xNSxJx9YUVWvjMunzmPLAQzLQMTLOVdTBQ cqHwNbnQ1gU02/mPgVnQM1h/m+jEe0VfjBeJWcF5O49gxZSzGzWotZnshfJQyVT6M4s1Jg5i7Hfn2 J7E4OeexgWX4EO9qPeBmDVcMSCT+fFgzO0smNVTIKPQD5v5tLNTufOpQfUNbn9DTUHvrbn+8zpXON ojfNZVUw==; Received: by zero.zsh.org with local id 1rvf5e-000DDX-Ri; Sat, 13 Apr 2024 15:14:50 +0000 Authentication-Results: zsh.org; iprev=pass (mta04.eastlink.ca) smtp.remote-ip=24.224.136.10; dmarc=none header.from=eastlink.ca; arc=none Received: from mta04.eastlink.ca ([24.224.136.10]:50307) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rvf54-000CVf-LZ; Sat, 13 Apr 2024 15:14:16 +0000 Received: from csp01.eastlink.ca ([71.7.199.166]) by mta04.eastlink.ca ([24.224.136.10]) with ESMTPS id <0SBV0EWTLZL93XG0@mta04.eastlink.ca> for zsh-users@zsh.org; Sat, 13 Apr 2024 12:14:13 -0300 (ADT) Received: from [192.168.0.11] (host-24-207-19-13.public.eastlink.ca [24.207.19.13]) by csp01.eastlink.ca ([71.7.199.166]) with ESMTPSA id vf52ruLl6Aimnvf53r1QvS (version=TLSv1_2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256); Sat, 13 Apr 2024 12:14:13 -0300 X-Authority-Analysis: v=2.4 cv=Q8Rx4J2a c=1 sm=1 tr=0 ts=661aa145 a=e7T7DzMKK1R988ZCg0wLyw==:117 a=e7T7DzMKK1R988ZCg0wLyw==:17 a=r77TgQKjGQsHNAKrUKIA:9 a=y6oNjZz3aFBQ8THoIo0A:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=gir0-LH0AAAA:8 a=4kn3O7cL7XoSYjdFK98A:9 a=lBL8BJOxhY5NTEtW:21 a=_W_S_7VecoQA:10 a=aLewGyoHDmJ4ULJHWpSz:22 X-Vade-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudeiiedgkeekucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecugfetuffvnffkpffmpdfqfgfvnecuuegrihhlohhuthemuceftddtnecunecujfgurheptgfkffggfgfuvfhfhfgjsegrtderredtvdejnecuhfhrohhmpeftrgihucetnhgurhgvfihsuceorhgrhigrnhgurhgvfihssegvrghsthhlihhnkhdrtggrqeenucggtffrrghtthgvrhhnpefhteethfevgeeuvdelgefgvdevudefueduffdvgfelvddvgfdtieegueeuleeifeenucfkphepvdegrddvtdejrdduledrudefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvdegrddvtdejrdduledrudefpdhhvghloheplgduledvrdduieekrddtrdduudgnpdhmrghilhhfrhhomheprhgrhigrnhgurhgvfihssegvrghsthhlihhnkhdrtggrpdhnsggprhgtphhtthhopedvpdhrtghpthhtohepreerpdhrtghpthhtohepiihshhdquhhsvghrshesiihshhdrohhrghdpghgvthdqkghiphfrrghsshifugepthhruhgv X-Vade-Score: 0 X-Vade-State: 0 X-EL-AUTH: rayandrews@eastlink.ca Content-type: multipart/alternative; boundary="------------Qp9ehrFYCyjF0uCL1CJqi0gw" Message-id: Date: Sat, 13 Apr 2024 08:14:12 -0700 MIME-version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: triviality regarding $# counts To: zsh-users@zsh.org References: <97793422-1543-4ba6-b52b-ff93eba03ab1@eastlink.ca> <7ba17739-6024-439b-a4a7-dd88fddfa2e4@eastlink.ca> <7333cf23-1fe7-4b3d-a7c1-f07697c5f062@eastlink.ca> <1e53a3f7-9bdb-45ae-81c7-7d0ec1a6a541@app.fastmail.com> <3cc19e86-e953-4e2f-9e57-30ff84f15fdf@eastlink.ca> Content-language: en-US From: Ray Andrews In-reply-to: <3cc19e86-e953-4e2f-9e57-30ff84f15fdf@eastlink.ca> X-Seq: 29803 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: This is a multi-part message in MIME format. --------------Qp9ehrFYCyjF0uCL1CJqi0gw Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit > I dunno. I've lost the example that I saved. Never mind, I'll keep an eye on it, and figure out next time. Red herring for now. It's a bit confusing looking into typeset -p output. All this 'splitting' stuff is not simple. For now everything works and I'm quite sure it's a bit more orthodox. > > A script: --------------------------------------------------------------------------------- redline () { echo -e "$red$@$nrm" } typeset -ga aaa=(" abc     def ghi     jkl mno     pqr ") redline "\naaa:" print -l $aaa redline "\naaa[1]:" print -l $aaa[1] redline "linecount of aaa is: $#aaa ... Single element!" ccc=( ${(@f)aaa} ) redline '\nccc=( ${(@f)aaa} )' print -l $ccc redline "linecount of ccc is: $#ccc ... split, but blank lines gone." ddd=( "${(@f)aaa}" ) redline '\nddd=( "${(@f)aaa}" ) ... it seems like a lot of trouble to copy the array as it is.' print -l "$ddd[@]"  #... don't forget the quotes, idiot!" redline "linecount of ddd is: $#ddd ... split, but blanks preserved and counted. NB EIGHT NOT SIX!" redline "\nddd[1]: That's right it's blank, just as it should be." print -l $ddd[1] redline "\nddd[2]:" print -l $ddd[2] redline "And now the typesets\n" typeset -p aaa typeset -p ccc typeset -p ddd # Verbatim: # typeset -a aaa=( $'\nabc\n\n\tdef ghi\n\tjkl mno\n\n\tpqr\n' ) # typeset -a ccc=( abc $'\tdef ghi' $'\tjkl mno' $'\tpqr' ) # typeset -a ddd=( '' abc '' $'\tdef ghi' $'\tjkl mno' '' $'\tpqr' '' ) # Aligned: Note the steeenking dollars ;-) ... and how they seem to replace the newlines. No? # typeset -a aaa=( $'\nabc  \n\n\tdef ghi  \n\tjkl mno \n\n\tpqr\n' )     #Original with blanks # typeset -a ccc=(     abc    $'\tdef ghi' $'\tjkl mno   ' $'\tpqr' )           #No blanks. # typeset -a ddd=(  '' abc '' $'\tdef ghi' $'\tjkl mno' '' $'\tpqr' '' )    #Blanks retained BUT not the same structure! ----------------------------------------------------------------------------------- ... so what about the dollars? Anyway, it comes clear: '${(@f)....}' doesn't ADD (or retain) newlines it removes them!  (Tho splitting the array where they used to be.) Doesn't need them cuz elements aren't separated by newlines (like I thought) but by ... however it's done.  Single quotes indicate elements.  And, best of all, copying an array, blanks and all, (not shown above) turns out to be simple: eee=( $aaa ) and: eee=( "{$(@f)aaa}" ) ... turns out to be a false equivalence where newlines are REMOVED. Don't be fooled by 'printf' -- it might not show you the genuine state of the array.  Scalars show their blank lines automatically but we need: print -l -- "$eee[@]" ... with arrays.  Trust typedef -p. --------------Qp9ehrFYCyjF0uCL1CJqi0gw Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
I dunno.  I've lost the example that I saved. Never mind, I'll keep an eye on it, and figure out next time. Red herring for now.  It's a bit confusing looking into typeset -p output. All this 'splitting' stuff is not simple. For now everything works and I'm quite sure it's a bit more orthodox.

   
A script:
---------------------------------------------------------------------------------

redline () { echo -e "$red$@$nrm" }

typeset -ga aaa=("
abc

    def ghi
    jkl mno

    pqr
")

redline "\naaa:"
print -l $aaa
redline "\naaa[1]:"
print -l $aaa[1]
redline "linecount of aaa is: $#aaa ... Single element!"

ccc=( ${(@f)aaa} )

redline '\nccc=( ${(@f)aaa} )'
print -l $ccc
redline "linecount of ccc is: $#ccc ... split, but blank lines gone."

ddd=( "${(@f)aaa}" )

redline '\nddd=( "${(@f)aaa}" ) ... it seems like a lot of trouble to copy the array as it is.'
print -l "$ddd[@]"  #... don't forget the quotes, idiot!"
redline "linecount of ddd is: $#ddd ... split, but blanks preserved and counted. NB EIGHT NOT SIX!"

redline "\nddd[1]: That's right it's blank, just as it should be."
print -l $ddd[1]
redline "\nddd[2]:"
print -l $ddd[2]

redline "And now the typesets\n"
typeset -p aaa
typeset -p ccc
typeset -p ddd

# Verbatim:

# typeset -a aaa=( $'\nabc\n\n\tdef ghi\n\tjkl mno\n\n\tpqr\n' )
# typeset -a ccc=( abc $'\tdef ghi' $'\tjkl mno' $'\tpqr' )
# typeset -a ddd=( '' abc '' $'\tdef ghi' $'\tjkl mno' '' $'\tpqr' '' )

# Aligned: Note the steeenking dollars ;-) ... and how they seem to replace the newlines. No?

# typeset -a aaa=( $'\nabc  \n\n\tdef ghi  \n\tjkl mno   \n\n\tpqr\n' )     #Original with blanks
# typeset -a ccc=(     abc    $'\tdef ghi' $'\tjkl mno   ' $'\tpqr' )           #No blanks.
# typeset -a ddd=(  '' abc '' $'\tdef ghi' $'\tjkl mno' '' $'\tpqr' '' )    #Blanks retained BUT not the same structure!

-----------------------------------------------------------------------------------

... so what about the dollars?

Anyway, it comes clear: '${(@f)....}' doesn't ADD (or retain) newlines it removes them!  (Tho splitting the array where they used to be.) Doesn't need them cuz elements aren't separated by newlines (like I thought) but by ... however it's done.  Single quotes indicate elements.  And, best of all, copying an array, blanks and all, (not shown above) turns out to be simple:

eee=( $aaa ) and:

eee=( "{$(@f)aaa}" )

... turns out to be a false equivalence where newlines are REMOVED.  Don't be fooled by 'printf' -- it might not show you the genuine state of the array.  Scalars show their blank lines automatically but we need:

print -l -- "$eee[@]"

... with arrays.  Trust typedef -p.


--------------Qp9ehrFYCyjF0uCL1CJqi0gw--