* Printing empty array elements
@ 2018-10-31 8:19 Jesper Nygårds
2018-10-31 8:31 ` Jesper Nygårds
0 siblings, 1 reply; 4+ messages in thread
From: Jesper Nygårds @ 2018-10-31 8:19 UTC (permalink / raw)
To: Zsh Users
[-- Attachment #1: Type: text/plain, Size: 382 bytes --]
Consider the following:
% rlines=("${(@f)$(print a; print; print c)}")
% for (( i=1; $i<=$#rlines; i+=1 )); do print $rlines[$i]; done
a
c
% print -l $rlines
a
c
In other words, "print -l" doesn't print empty array elements (or perhaps
it never even sees them?). Is there a way to make it not omit empty
elements when printing an array, apart from iterating over the elements?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Printing empty array elements
2018-10-31 8:19 Printing empty array elements Jesper Nygårds
@ 2018-10-31 8:31 ` Jesper Nygårds
2018-10-31 10:00 ` Mikael Magnusson
0 siblings, 1 reply; 4+ messages in thread
From: Jesper Nygårds @ 2018-10-31 8:31 UTC (permalink / raw)
To: Zsh Users
[-- Attachment #1: Type: text/plain, Size: 155 bytes --]
Aargh. Twenty years of shell programming, and still I'm making rookie
mistakes when it comes to quoting. The answer is of course:
% print -l "$rlines[@]"
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Printing empty array elements
2018-10-31 8:31 ` Jesper Nygårds
@ 2018-10-31 10:00 ` Mikael Magnusson
2018-10-31 10:29 ` Jesper Nygårds
0 siblings, 1 reply; 4+ messages in thread
From: Mikael Magnusson @ 2018-10-31 10:00 UTC (permalink / raw)
To: Jesper Nygårds; +Cc: Zsh Users
On 10/31/18, Jesper Nygårds <jesper.nygards@gmail.com> wrote:
> Aargh. Twenty years of shell programming, and still I'm making rookie
> mistakes when it comes to quoting. The answer is of course:
>
> % print -l "$rlines[@]"
You can also use "${(@)rlines}" as in the first line of your code
(which is also necessary if you want to use a subscript range).
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Printing empty array elements
2018-10-31 10:00 ` Mikael Magnusson
@ 2018-10-31 10:29 ` Jesper Nygårds
0 siblings, 0 replies; 4+ messages in thread
From: Jesper Nygårds @ 2018-10-31 10:29 UTC (permalink / raw)
To: Zsh Users
[-- Attachment #1: Type: text/plain, Size: 273 bytes --]
On Wed, Oct 31, 2018 at 11:00 AM Mikael Magnusson <mikachu@gmail.com> wrote:
> You can also use "${(@)rlines}" as in the first line of your code
> (which is also necessary if you want to use a subscript range).
Thank you, that's a great tip. Didn't see the connection.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-10-31 10:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-31 8:19 Printing empty array elements Jesper Nygårds
2018-10-31 8:31 ` Jesper Nygårds
2018-10-31 10:00 ` Mikael Magnusson
2018-10-31 10:29 ` Jesper Nygårds
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).