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

Re: How to create unnamed temporary arrays?



Hannu Koivisto wrote:

> Greetings,
> 
> I'm currently using something like this to list the base names of
> files in /usr/local/etc/packages/ directory, each name on its own
> line:
> 
> echo ${(F)$(echo /usr/local/etc/packages/*(.:t:r))}
> 
> This has the obvious problem that it doesn't work if filenames have
> spaces in them.  I just couldn't figure out any way to do something
> corresponding to:
> 
> kala=(/usr/local/etc/packages/*(.:t:r))
> echo ${(F)kala}
> 
> without creating that temporary array variable.  Not that this
> really matters in this case, but I've faced situations earlier
> where avoiding the temporary name might have been more convenient
> and now I finally have a simple enough example to demonstrate it.
> 
> So, is there a way?  I'm using zsh versions 3.1.9-dev-6 and
> 3.1.9-dev-8 from Debian GNU/Linux testing/unstable and stable,
> respectively.

If I got that right and you really only want those filenames one per
line, you can just use:

  print -l /usr/local/etc/packages/*(.:t:r)

(the -l option to print makes it print the argument one per line).

Bye
 Sven


--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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