zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: counting trouble
Date: Wed, 4 Apr 2018 21:48:51 -0700	[thread overview]
Message-ID: <180404214851.ZM25425@torch.brasslantern.com> (raw)
In-Reply-To: <83ca0dfb-b91f-31d8-5346-c2794f7d8658@eastlink.ca>

On Apr 4,  7:07pm, Ray Andrews wrote:
}
} On 04/04/18 06:15 PM, Bart Schaefer wrote:
} > 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

But it's NOT lines, any more than the elements of a C array are lines
(and internally, to zsh at least, it *IS* a C array of nul-terminated
strings -- other shells such as bash use a linked list, etc.).

In the shell grammar sense, it's an array of "shell words".

A directory does not contain "lines", it contains file names.  When you
use a glob, you're extracting the matching file names one by one, not
grepping a text stream of all those names and then splitting it up at
line breaks.

}    print -l "${tmp[@]}\n"
} 
} ... does exactly what I'm expecting

But print is receiving individual "shell words" as its argument list,
one array element per word.  The -l option causes print to *add* the
line breaks.  If you replace -l with -N you don't get line breaks,
you get nul bytes.

(Except given that construction plus print's usual interpretation of
backslash-escapes, you've pasted an extra newline on the final word.)
 
} 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.

There's no perfect way to do that because there's intentionally no
character that you could use to show where the words begin and end
that can't also theoretically appear IN one of the words.  You could
step in with a debugger like gdb and use it to display the internal
memory allocations.

If you know you're writing to an ANSI color terminal and you know the
array doesn't contain color changing sequences, you can try something
like this:

    autoload colors
    colors
    wstart="$bg[black]$fg[green]<<$reset_color"
    wend="$bg[black]$fg[yellow]>>$reset_color"
    printf "${wstart}%s${wend}" "${array[@]}"
    print

Adjust wstart and wend until you have something you think is visible
enough.

} If I could see the hidden structure of both input and output there'd
} be a lot less guessing.

I'm not sure what you consider to be an "input" and what an "output".


  reply	other threads:[~2018-04-05  4:49 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
2018-04-05  4:48     ` Bart Schaefer [this message]
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=180404214851.ZM25425@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --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).