* 2012-05-08 11:46 +0200 Jan Kohnert:
> Am 2012-05-08 11:31, schrieb Urs Liska:
> > I would like to write a script that allows me to compile all .ly
> > files in one run.
>
> [...]
>
> This would be a bash solution:
> 
> for dir in $(find . -maxdepth 1 -type d -regex "^\.\/[0-9].*$"); do
>     cd {dir}
>     lilypond *.ly
>     cd ..
> done

This is guaranteed to fail as soon as any found directory name contains 
any sort of whitespace. 

[Fun fact: the ONLY characters you can rely on not appearing in a Unix 
file name are the forward slash and the null byte.]

It's overkill in this case anyway (see Jonas' or David's replies), but 
if you really want to explicitly loop over the output of a find command 
call, the proper way to do it is to make it output a list of null-byte 
separated strings with the -print0 option and then use an appropriate 
shell script construct to loop over this. A solid way to do it in bash 
is the following useful idiom:


while IFS= read -r -u3 -d $'\0' FOUND; do
    # do what you want with "$FOUND"
    ...
done 3< <(find [OTHER OPTIONS AS REQUIRED] -print0)


Explanation and alternatives:
<http://stackoverflow.com/a/1120952>
<http://mywiki.wooledge.org/BashFAQ/020>


R.S.

_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to