zsh-users
 help / Atom feed
* 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, back to index

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

zsh-users

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-users

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.users


AGPL code for this site: git clone https://public-inbox.org/ public-inbox