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

Re: Command for random? recursive?



I think I got it now,
I make a script called 'recurse' with these lines:
----------------------------------------------
for file in $(find . -name '*.txt' -print); do
        $1 $file
done
----------------------------------------------

or

----------------------------------------------
for file in $(find . -name '*.mpg' -print); do
        $1 $file
----------------------------------------------
then I simply type in bash# recurse mplayer
or bash# recurse mkztxt

works great now (for ztxt), but whenever it opens mplayer it closes the
window immediately before playing and plays the next file, this keeps
going until the end of the mpg files. Can I delay the recursing until
the current file is done playing?


Many thanks for the help :)
Elijah


On Mon, 2002-12-30 at 18:29, Bob Proulx wrote:
> 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]* //'
>   done
> 
>   randomplaylist=$(for file in $(find . -name '*.mpg' -print); do
>     echo $RANDOM $file | sort -n | sed 's/^[0-9][0-9]* //'
>   done)
> 
> 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.  :-)
> 
> Bob




Reply to: