June Tate wrote:
> 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 * june@theonelab.com
>
I humbly sit corrected. Good job June, and thanks!
I should have realized this once I thought about it. IOW, the -exec'd
command is executed for each file found, not once for the entire list.
That seems obvious when considering find's -ok option.
--
-Eric 'shubes'
"There is no such thing as the People;
it is a collectivist myth.
There are only individual citizens
with individual wills
and individual purposes."
-William E. Simon (1927-2000),
Secretary of the Treasury (1974-1977)
"A Time For Truth" (1978), pg. 237
---------------------------------------------------
PLUG-discuss mailing list -
PLUG-discuss@lists.plug.phoenix.az.us
To subscribe, unsubscribe, or to change you mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss