The situation is, I have an MP3 player mpg321
that accepts a list of files as argument. I keep my music in a directory named "music", in which there are a few more directories. I just want to play all of them, so I run the program with
mpg321 $(find /music -iname "*\.mp3")
. The problem is, some file names have whitespace in them, and the program breaks those names into smaller parts and complains about missing files. Wrapping the result of find
in quotes
mpg321 "$(find /music -iname "*\.mp3")"
does not help because all will become one big "file name", which is obviously not found.
How can I do this then? If that matters, I am using bash
, but will be switching to zsh
soon.
Best Answer
Try using find's
-print0
or-printf
option in combination withxargs
like this:How this works is explained by find's manual page: