Re: bash scripting: mplayer command line playlist

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: June Tate
Date:  
To: plug-discuss
Subject: Re: bash scripting: mplayer command line playlist
On Feb 19, 2005, at 9:12 AM, Eric "Shubes" wrote:

> Nathan England wrote:
>> On Friday 18 February 2005 10:25, Eric "Shubes" wrote:
>>> Mike Hoy wrote:
>>>
>>> find music/ -name '*.mp3' -exec mplayer -shuffle {} \;
>>>
>>> Note, you probably want to add the full path to your music/
>>> directory.
>> This would tell mplayer to shuffle the 1 song it sent, right?
>
> Bsst. Wrong.


You sure about that? Because according to the man page for find, "If
the string ``{}'' appears anywhere in the utility name or the arguments
it is replaced by the pathname _of the current file_" (emphasis added,
gleaned from the MacOS X Panther "man find", but also found in Debian's
man page around line 262).

So according to this, what find will do is essentially the same thing
that a "for i in $LIST; do $COMMAND; done" would do, and that is call
"mplayer -shuffle $i" for every file that is found, with one on each
command. Essentially it would be equivalent to doing this:

     foo@bar:~$ mplayer -shuffle $file1
     foo@bar:~$ mplayer -shuffle $file2
     foo@bar:~$ mplayer -shuffle $file3
     (...ad infinitum...)


To pass the _entire_ list to mplayer as a -shuffle argument list
instead, do it like this:

     foo@bar:~$ mplayer -shuffle $(find music/ -name '*.mp3')


A good way to illustrate this is to instead pass the arguments to the
printf command. If we call printf like this:

     foo@bar:~$ printf "%s\n" $(find music/ -name '*.mp3')


You'll notice that all of the filenames that find finds are printed
right next to each other, separated by a space. If we do it like this,
however:

     foo@bar:~$ find music/ -name '*.mp3' -exec printf "%s" '{}' ';'


Each filename is printed on a separate line, because of the same effect
mentioned above. What we want is to pass the entire results of the
search to mplayer, so we should use the $(find ...) form instead of the
find -exec form.

HTH =o)

--
June Tate * http://www.theonelab.com *


---------------------------------------------------
PLUG-discuss mailing list -
To subscribe, unsubscribe, or to change you mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss