zsh-users
 help / color / mirror / code / Atom feed
From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: triviality regarding $# counts
Date: Fri, 12 Apr 2024 18:13:17 -0700	[thread overview]
Message-ID: <7ba17739-6024-439b-a4a7-dd88fddfa2e4@eastlink.ca> (raw)
In-Reply-To: <CAH+w=7Y2ayDcxx0NF634cZXurn792B1_B4CSzSmryLU3-fhRHg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2398 bytes --]


On 2024-04-12 12:09, Bart Schaefer wrote:
> None of that is about $#. $# just counts either characters in a
> string or elements in an array, full stop.
Right, it's a question of getting the splitting correct.
> What you're asking for is a dissertation on how to split text into
> arrays.  I have no idea what you mean by "without spaces" and there's
> no inherent definition of a "paragraph"
I know it, thus the air-quotes, In one of my tests I had three 
consecutive outputs from aptitude written to the array and at some point 
the count was 3, so somehow each separate output got merged into one 
element.
> so the best you could get from
> this is characters, words, and lines -- but even for words you need to
> explain whether you mean "shell words" (separated by $IFS characters)
> or something else, including whether quotes matter.
It is a bit confusing.

>    Further, you seem
> to be starting from scalar text sometimes, and text that's already
> split into an array other times -- in the latter case you have to
> explain whether and how you want the array re-joined into a block of
> text before re-splitting.
I've got a whole bunch of that figured out today.  What I thought were 
arrays were scalars that just happened to print nicely on separate lines 
where wanted but not due to '\n''s.  And what I thought line splitting 
-- (f) -- did was enter '\n's into the body of the variable -- a guy 
might be forgiven for thinking that -- but no it's dollar signs.  And 
efforts to force '\n's' were disastrous. Some quality time with typedef 
-p really helped.  Sorta funny, everything was working fine, but there 
were hidden disasters lurking that surfaced for that most trivial of 
reasons -- but forced me to redo quite a bit of stuff where things 
really are arrays and nevermind the '\n's.  And I get my line counts 
honestly now :-)  One thing: it sure is hard to hang on to blank lines.  
I wish there was some option to default to preserving them.
> The shell is not a word processor and doesn't understand your
> conceptualization of text formatting.
Very true.  But I focus on what I can see and if it looks right it's 
easy to think it is right.  Anyway, thanks to Lawrence much as been 
learned. BTW $# is a very convenient way of detecting how things are 
split, now that I know that scalars always return character counts and 
arrays, element counts.  Easy!

[-- Attachment #2: Type: text/html, Size: 3604 bytes --]

  reply	other threads:[~2024-04-13  1:14 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-11  0:56 Ray Andrews
2024-04-12  4:55 ` Lawrence Velázquez
2024-04-12 14:48   ` Ray Andrews
2024-04-12 19:09     ` Bart Schaefer
2024-04-13  1:13       ` Ray Andrews [this message]
2024-04-13  1:33         ` Mark J. Reed
2024-04-13  2:28           ` Ray Andrews
2024-04-13  3:25             ` Lawrence Velázquez
2024-04-13 14:37               ` Ray Andrews
2024-04-13 15:14                 ` Ray Andrews
2024-04-13 17:19                   ` Mark J. Reed
2024-04-13 17:27                     ` Mark J. Reed
2024-04-13 18:08                       ` Ray Andrews
2024-04-13 19:45                         ` Bart Schaefer
2024-04-13 20:36                           ` Ray Andrews
2024-04-13 21:01                             ` Bart Schaefer
2024-04-14  0:28                               ` Ray Andrews
2024-04-14  0:30                               ` Lawrence Velázquez
2024-04-14  3:26                                 ` Ray Andrews
2024-04-14  3:49                                   ` Lawrence Velázquez
2024-04-14  4:57                                     ` Bart Schaefer
2024-04-14 13:24                                       ` Ray Andrews
2024-04-14 13:35                                         ` Roman Perepelitsa
2024-04-14 14:06                                           ` Ray Andrews
2024-04-14 14:15                                             ` Roman Perepelitsa
2024-04-14 14:53                                               ` Ray Andrews
2024-04-14 15:11                                                 ` Mark J. Reed
2024-04-14 16:23                                                   ` Ray Andrews
2024-04-14 14:06                                         ` Mark J. Reed
2024-04-14 14:47                                           ` Ray Andrews
2024-04-14 14:59                                             ` Mark J. Reed
2024-04-14 15:51                                         ` Bart Schaefer
2024-04-14 17:22                                           ` Ray Andrews
2024-04-14 17:42                                             ` Mark J. Reed
2024-04-14 18:24                                               ` Bart Schaefer
2024-04-14 22:00                                               ` Ray Andrews
2024-04-13 20:11                         ` Mark J. Reed
2024-04-13 20:53                   ` Bart Schaefer
2024-04-14  0:19                     ` Ray Andrews
2024-04-13  1:35         ` Bart Schaefer

Reply instructions:

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7ba17739-6024-439b-a4a7-dd88fddfa2e4@eastlink.ca \
    --to=rayandrews@eastlink.ca \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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

	https://git.vuxu.org/mirror/zsh/

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).