From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: counting trouble
Date: Wed, 4 Apr 2018 19:07:53 -0700 [thread overview]
Message-ID: <83ca0dfb-b91f-31d8-5346-c2794f7d8658@eastlink.ca> (raw)
In-Reply-To: <CAH+w=7bJHzWRq9W8TCog1hR=8gi48X8S64sK6tNw8NQTVzDiCQ@mail.gmail.com>
On 04/04/18 06:15 PM, Bart Schaefer wrote:
> On Wed, Apr 4, 2018 at 11:21 AM, Ray Andrews <rayandrews@eastlink.ca> wrote:
>>
>> That can't be all there is to it. $#array only becomes a count of
>> characters if the context forces the array into string form. Which
>> admittedly can happen in some non-obvious ways, but what you've shown
>> above is not one of those ways. What are you really doing?
I'll take another look, that's a good clue anyway.
>
>> Hacking away I find this works:
>>
>> [ -e "$1" ] && tmp=( "${(f)${1}}" ) || tmp=( ${1}*(N) )
> Umm ... [ -e "$1" ] will only succeed for a single literal file name,
Exactly the point of it. I found I had to handle an exact match
specially. I'm sure there's a better way.
> expected this to work: " ${(f)${1}*} " but it doesn't.
> Expected it to do what? Filename generation like ${1}* out in the
> open (so to speak)?
Yeah, but as I said, I've figured out that that won't happen, it's not a
glob 'inside'. So how would I get the results of the glob 'inside' as
well as the single match not counting characters? .... but you've just
said that shouldn't be happening, so I'll follow that clue.
> What led you to expect that? In any case
> filename generation would never produce a newline-separated string
> (again barring files with newlines in the name), so (f) would not do
> anything to the result.
>
> Please don't think about globbing as returning "lines". It doesn't.
>
But:
tmp=( ${1}*(N) )
... seems to give me exactly that -- an array split on lines with no
worries about spaces in filenames. And '$#' counts the number of files
just as I want.
print -l "${tmp[@]}\n"
... does exactly what I'm expecting (bottom example):
15 /aWorking/Zsh/Source/Wk 3 $ . try; find_match try,12
Exact match found: "try,12"
15 /aWorking/Zsh/Source/Wk 3 $ . try; find_match try,1
Unique match found: "try,1"
15 /aWorking/Zsh/Source/Wk 3 $ . try; find_match try,14
Exact match found: "try,14,interim"
15 /aWorking/Zsh/Source/Wk 3 $ . try; find_match try,*
ERROR: No wildcards please
15 /aWorking/Zsh/Source/Wk 3 $ . try; find_match try,
ERROR: 18:: 15 matches for "try,", please disambiguate or copy manually:
try,1
try,10,working
try,11,very nice, help text
try,12
try,13
try,14,interim
try,15,important noglob and messages
try,2,exact match handled
try,3,now add declare
try,4,no ls
try,5,shakeout bugs
try,6,interim safe
try,7,now with find_match
try,8
try,9,working
===========================================
What would be manna from heaven is to be able to look at an array and
'see' the construction of it -- how it's split, if one could see the
newlines and/or spaces in both input and output that would be huge.
Even after several years I still find myself throwing syntax at things
hopefully but almost randomly until eventually something works. If I
could see the hidden structure of both input and output there'd be a lot
less guessing.
next prev parent reply other threads:[~2018-04-05 2:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-04 18:21 Ray Andrews
2018-04-05 1:15 ` Bart Schaefer
2018-04-05 2:07 ` Ray Andrews [this message]
2018-04-05 4:48 ` Bart Schaefer
2018-04-05 13:45 ` Ray Andrews
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=83ca0dfb-b91f-31d8-5346-c2794f7d8658@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).