Originally Posted by mrmnemo
I seem to remember reading somehting about the way that bash interpets a line. I guess a way of telling bash to read the brackets as part of the commands rather than to enclose another command. er, thats why.
Except that grail's question was about why
you want to do this in the first place. Parentheses in find
are only needed to group expressions together to enforce precedence. In this case it appears you simply want both tests to be evaluated equally, so they are unnecessary. Just use...
find /media/music/ -depth -name "*.m4a" -o -name "*.wma
But to answer your actual question, $(..)
is a subshell. Simply treat everything inside it as if it were on a separate line.
for f in $( find /media/music/ -depth \( -name "*.m4a" -o -name "*.wma \) )
Also note that $((..))
is a separate operator that expands arithmetical expressions.
Finally, it may have been mentioned before, but a for
loop is not recommended when the input is from a command that generates filenames or other strings that can include spaces. This is because for
reads each word
as a separate input, and can't distinguish lexical whitespace from syntactical whitespace (at least not without futzing about with IFS).
Use a while+read
loop instead, with process substitution for input. Since read
works on a per-line basis, rather than per-word, each line from find
will be safely accepted as the complete filename that it is (barring the unlikely possibility of encountering a filename that itself contains a newline character).
while read f ; do
done < <( find /media/music/ -depth -name "*.m4a" -o -name "*.wma" )