zsh-users
 help / color / mirror / code / Atom feed
From: "Lawrence Velázquez" <larryv@zsh.org>
To: "Ray Andrews" <rayandrews@eastlink.ca>
Cc: zsh-users@zsh.org
Subject: Re: The elements of enlightenment
Date: Tue, 06 Dec 2022 01:39:01 -0500	[thread overview]
Message-ID: <19107309-e5a4-4e41-8bfc-48cb46fb727d@app.fastmail.com> (raw)
In-Reply-To: <54bcd6dd-e589-4696-f042-1155b78df9d2@eastlink.ca>

On Mon, Dec 5, 2022, at 10:57 AM, Ray Andrews wrote:
> By double quoting: ( "$( setopt )" ) we seem to have 
> solved the problem, it prints correctly.  But trouble lurks in the 
> shadows.   I do this:
>
>      $  list=( "${list[@]/ off/${red} off${nrm}}" )
>
> ... And I'm baffled that only the very first 'off' is colorized. Why?  
> Because '$#list' = 1!  It looks like we have each line as a separate 
> element but we don't.  It only looks that way because the newlines in 
> the output are still in there, they aren't 'print -l' newlines, they're 
> newlines in the data itself!! They look the same but they are *not* the 
> same.

As an aside, simply printing out data structures' contents is an
unreliable debugging tool, for reasons you have just discovered.

	% arr=($'a\nb\rc' $'d\re\nf')
	% print -l $arr
	a
	c
	e
	f

A better tool is "typeset -p", which outputs an accurate (albeit
sometimes difficult-to-read) representation.

	% typeset -p arr
	typeset -a arr=( $'a\nb\C-Mc' $'d\C-Me\nf' )

-- 
vq


      parent reply	other threads:[~2022-12-06  6:40 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-05 15:57 Ray Andrews
2022-12-05 16:24 ` Roman Perepelitsa
2022-12-05 18:30   ` Bart Schaefer
2022-12-05 19:35   ` Ray Andrews
2022-12-05 19:44     ` Bart Schaefer
2022-12-05 19:58     ` Roman Perepelitsa
2022-12-05 21:20       ` Ray Andrews
2022-12-05 21:49         ` Roman Perepelitsa
2022-12-05 23:52           ` Ray Andrews
2022-12-06  0:17             ` Bart Schaefer
2022-12-06  1:34               ` Ray Andrews
2022-12-06 18:55             ` Roman Perepelitsa
2022-12-06 19:45               ` Bart Schaefer
2022-12-06 20:01                 ` Roman Perepelitsa
2022-12-06 20:07                   ` Bart Schaefer
2022-12-06 20:22                     ` Roman Perepelitsa
2022-12-06 23:52               ` Lawrence Velázquez
2022-12-07  1:04                 ` Lawrence Velázquez
2022-12-05 21:49         ` Bart Schaefer
2022-12-05 21:51           ` Bart Schaefer
2022-12-05 22:24           ` Ray Andrews
2022-12-05 23:24             ` Bart Schaefer
2022-12-06  1:47               ` Ray Andrews
2022-12-06  6:39 ` Lawrence Velázquez [this message]

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=19107309-e5a4-4e41-8bfc-48cb46fb727d@app.fastmail.com \
    --to=larryv@zsh.org \
    --cc=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).