zsh-users
 help / color / mirror / code / Atom feed
* arrays and spaces in file names?
@ 2006-05-24 20:08 reckoner
  2006-05-25 15:05 ` Mikael Magnusson
  2006-05-25 15:08 ` Marc Chantreux
  0 siblings, 2 replies; 8+ messages in thread
From: reckoner @ 2006-05-24 20:08 UTC (permalink / raw)
  To: zsh-users

I want to do something like

% names=(`find . -print`)

and then something like

% for i in names do;...;done

The problem is that some of the filenames have spaces in them and the 
array elements split on these spaces. I read the manpage and can't make 
sense of what to do w/ this.

Help?

Thanks.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: arrays and spaces in file names?
  2006-05-24 20:08 arrays and spaces in file names? reckoner
@ 2006-05-25 15:05 ` Mikael Magnusson
  2006-05-25 15:10   ` Marc Chantreux
  2006-05-25 21:32   ` sam reckoner
  2006-05-25 15:08 ` Marc Chantreux
  1 sibling, 2 replies; 8+ messages in thread
From: Mikael Magnusson @ 2006-05-25 15:05 UTC (permalink / raw)
  To: zsh-users; +Cc: reckoner

On 5/24/06, reckoner <sam.reckoner@gmail.com> wrote:
> I want to do something like
>
> % names=(`find . -print`)
>
> and then something like
>
> % for i in names do;...;done
>
> The problem is that some of the filenames have spaces in them and the
> array elements split on these spaces. I read the manpage and can't make
> sense of what to do w/ this.
>
> Help?

Try this,
for i in **/*(.); do foo; bar;  done

> Thanks.

-- 
Mikael Magnusson

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: arrays and spaces in file names?
  2006-05-24 20:08 arrays and spaces in file names? reckoner
  2006-05-25 15:05 ` Mikael Magnusson
@ 2006-05-25 15:08 ` Marc Chantreux
  1 sibling, 0 replies; 8+ messages in thread
From: Marc Chantreux @ 2006-05-25 15:08 UTC (permalink / raw)
  To: zsh-users

reckoner a écrit :

> I want to do something like
>
> % names=(`find . -print`)

the result is splitted with IFS. If you want each lines to be an element 
if your array, use (f) flag.

names=(${(f)"$(find  . -print)"})

for f ( $names ) print $f

OT but can help : you don't need find as ** can search files recursively :

names=( **/* ) and names=(${(f)"$(find  . -print)"}) are equivalent

regards
mc


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: arrays and spaces in file names?
  2006-05-25 15:05 ` Mikael Magnusson
@ 2006-05-25 15:10   ` Marc Chantreux
  2006-05-25 16:56     ` Paul Ackersviller
  2006-05-25 21:32   ` sam reckoner
  1 sibling, 1 reply; 8+ messages in thread
From: Marc Chantreux @ 2006-05-25 15:10 UTC (permalink / raw)
  To: zsh-users

Mikael Magnusson a écrit :

>
> Try this,
> for i in **/*(.); do foo; bar;  done

not really :

find . -print works like **/*
find . -type f -print works like **/*(.)

regards


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: arrays and spaces in file names?
  2006-05-25 15:10   ` Marc Chantreux
@ 2006-05-25 16:56     ` Paul Ackersviller
  2006-05-25 17:53       ` Paul Ackersviller
  0 siblings, 1 reply; 8+ messages in thread
From: Paul Ackersviller @ 2006-05-25 16:56 UTC (permalink / raw)
  To: Marc Chantreux; +Cc: zsh-users

On Thu, May 25, 2006 at 05:10:41PM +0200, Marc Chantreux wrote:
> Mikael Magnusson a ??crit :
> 
> >
> >Try this,
> >for i in **/*(.); do foo; bar;  done
> 
> not really :
> 
> find . -print works like **/*
> find . -type f -print works like **/*(.)

You'll also need to setopt GLOB_DOTS, aka DOT_GLOB, to match what find
will give you, i.e. include files with . on the front of theire names.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: arrays and spaces in file names?
  2006-05-25 16:56     ` Paul Ackersviller
@ 2006-05-25 17:53       ` Paul Ackersviller
  0 siblings, 0 replies; 8+ messages in thread
From: Paul Ackersviller @ 2006-05-25 17:53 UTC (permalink / raw)
  To: Marc Chantreux; +Cc: zsh-users

On Thu, May 25, 2006 at 04:56:58PM +0000, Paul Ackersviller wrote:
> On Thu, May 25, 2006 at 05:10:41PM +0200, Marc Chantreux wrote:
> > Mikael Magnusson a ??crit :
> > 
> > >
> > >Try this,
> > >for i in **/*(.); do foo; bar;  done
> > 
> > not really :
> > 
> > find . -print works like **/*
> > find . -type f -print works like **/*(.)
> 
> You'll also need to setopt GLOB_DOTS, aka DOT_GLOB, to match what find
> will give you, i.e. include files with . on the front of their names.

Or more succinctly (I reply to myself):

find . -type f -print works like **/*(.D)


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: arrays and spaces in file names?
  2006-05-25 15:05 ` Mikael Magnusson
  2006-05-25 15:10   ` Marc Chantreux
@ 2006-05-25 21:32   ` sam reckoner
  2006-05-26  0:22     ` Eric Mangold
  1 sibling, 1 reply; 8+ messages in thread
From: sam reckoner @ 2006-05-25 21:32 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: zsh-users

[-- Attachment #1: Type: text/plain, Size: 641 bytes --]

I need the intermediate step of putting the filenames in an array for other
reasons.

Thanks!



On 5/25/06, Mikael Magnusson <mikachu@gmail.com> wrote:
>
> On 5/24/06, reckoner <sam.reckoner@gmail.com> wrote:
> > I want to do something like
> >
> > % names=(`find . -print`)
> >
> > and then something like
> >
> > % for i in names do;...;done
> >
> > The problem is that some of the filenames have spaces in them and the
> > array elements split on these spaces. I read the manpage and can't make
> > sense of what to do w/ this.
> >
> > Help?
>
> Try this,
> for i in **/*(.); do foo; bar;  done
>
> > Thanks.
>
> --
> Mikael Magnusson
>

[-- Attachment #2: Type: text/html, Size: 1053 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: arrays and spaces in file names?
  2006-05-25 21:32   ` sam reckoner
@ 2006-05-26  0:22     ` Eric Mangold
  0 siblings, 0 replies; 8+ messages in thread
From: Eric Mangold @ 2006-05-26  0:22 UTC (permalink / raw)
  To: sam reckoner, Mikael Magnusson; +Cc: zsh-users

names=( **/*(.) )

-Eric Mangold

On Fri, 26 May 2006 07:32:13 +1000, sam reckoner <sam.reckoner@gmail.com>  
wrote:

> I need the intermediate step of putting the filenames in an array for  
> other
> reasons.
>
> Thanks!
>
>
>
> On 5/25/06, Mikael Magnusson <mikachu@gmail.com> wrote:
>>
>> On 5/24/06, reckoner <sam.reckoner@gmail.com> wrote:
>> > I want to do something like
>> >
>> > % names=(`find . -print`)
>> >
>> > and then something like
>> >
>> > % for i in names do;...;done
>> >
>> > The problem is that some of the filenames have spaces in them and the
>> > array elements split on these spaces. I read the manpage and can't  
>> make
>> > sense of what to do w/ this.
>> >
>> > Help?
>>
>> Try this,
>> for i in **/*(.); do foo; bar;  done
>>
>> > Thanks.
>>
>> --
>> Mikael Magnusson
>>



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2006-05-26  0:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-05-24 20:08 arrays and spaces in file names? reckoner
2006-05-25 15:05 ` Mikael Magnusson
2006-05-25 15:10   ` Marc Chantreux
2006-05-25 16:56     ` Paul Ackersviller
2006-05-25 17:53       ` Paul Ackersviller
2006-05-25 21:32   ` sam reckoner
2006-05-26  0:22     ` Eric Mangold
2006-05-25 15:08 ` Marc Chantreux

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).