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

Re: triviality regarding $# counts



On Fri, Apr 12, 2024 at 7:49 AM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> For now, what I'm wishing for is a nice, focused essay: "How to use '$#' to count whatever it is you want to count -- characters, words, lines, paragraphs (at one point my count was '3' which I'd approximate to being a paragraph) ... and all with or without spaces and/or empty lines. "

None of that is about $#.  $# just counts either characters in a
string or elements in an array, full stop.

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

The shell is not a word processor and doesn't understand your
conceptualization of text formatting.




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