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

Re: The elements of enlightenment



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




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