Frank Gevaerts <[EMAIL PROTECTED]> [2002-12-07 19:58:00 +0100]:
> On Sat, Dec 07, 2002 at 11:47:54AM -0700, Bob Proulx wrote:
> > You are trying to find files in a directory.  Therefore I recommend
> > you use the 'find' command.
> > [..contrived.example...]
> >   mp3playlist=$(find . -name '*.jpg' -print)
> >   for mp3 in $mp3playlist; do
> >     mpg123 $mp3
> >   done
> 
> Why not just 
> find . -name \*.jpg -exec mpg123 {} \;
> ?
> 
> Much shorter, and no problems with number of arguments...

I was only proposing the mpg123 as an example.  I really don't know
what the OP wanted to do with it.

You are right that using find's exec and {} avoids the file with
spaces problem.  But instead I would use this if I wanted to play
every file.

  find . -name '*.jpg' -print0 | xargs -r0 mpg123

> However, be careful with find. If you do not want to search
> subdirectories, it is probably not what you want.

Not true!  Check out the -maxdepth option.  This only searches one
directory deep.  The second only operates on the command line files.

  find . -name '*.jpg' -maxdepth 1 -print0 | xargs -r0 mpg123
  find *.jpg -maxdepth 0 -print0 2>/dev/null | xargs -r0 mpg123

Bob

Attachment: msg17637/pgp00000.pgp
Description: PGP signature

Reply via email to