[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Command for random? recursive?

Elijah <desiderata@softhome.net> [2002-12-30 11:58:36 +0900]:
> On Mon, 2002-12-30 at 12:38, Jamin W. Collins wrote:
> > On Mon, Dec 30, 2002 at 11:37:31AM +0900, Elijah wrote:
> > 
> > > 1. How do you perform a command to do things recursively? for example
> > > mplayer -vo xv -ao sdl *.mpg doesn't seem to work, also when I'm
> > > making zTXT files - mkztxt *.txt
> > 
> > Take a look at shell scripting.  Some applications natively support the

Here is a hint.  Use 'find' to find files.

  find . -name '*.mpg' -print

Let's assume there are no newlines or spaces in your filenames just to
keep things simple.  I use this with mpg123 to play a random
selection using the -Z (random order) option.

  mpg123 -Z $(find . -name '*.mp3' -print)

The $RANDOM variable in the shell is a random number generator.  You
can use this to shuffle the order yourself.  Here is one way of doing
this which you might find useful.

  for file in $(find . -name '*.mpg' -print); do
    echo $RANDOM $file | sort -n | sed 's/^[0-9][0-9]* //'

  randomplaylist=$(for file in $(find . -name '*.mpg' -print); do
    echo $RANDOM $file | sort -n | sed 's/^[0-9][0-9]* //'

This does not handle newlines or spaces in the filenames.  But it is
easier to understand than the script that does.  To handle those you
have to use the zero terminated string options 'sort -z', 'find
-print0', 'xargs -0', etc.  I will leave that as an exercise for the
reader.  :-)


Attachment: pgpLPMsIUbuDN.pgp
Description: PGP signature

Reply to: