[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: (somewhat OT:) lilypond calling bash script questions
From: |
Reedmace Star |
Subject: |
Re: (somewhat OT:) lilypond calling bash script questions |
Date: |
Wed, 09 May 2012 00:44:54 +0200 |
User-agent: |
KMail/4.8.2 (Linux/3.2.0-24-generic; KDE/4.8.2; x86_64; ; ) |
* 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.
- (somewhat OT:) lilypond calling bash script questions, Urs Liska, 2012/05/08
- Re: (somewhat OT:) lilypond calling bash script questions, address@hidden, 2012/05/08
- Re: (somewhat OT:) lilypond calling bash script questions, Jonas Olson, 2012/05/08
- Re: (somewhat OT:) lilypond calling bash script questions, David Kastrup, 2012/05/08
- Re: (somewhat OT:) lilypond calling bash script questions, Jan Kohnert, 2012/05/08
- Re: (somewhat OT:) lilypond calling bash script questions, Álex R . Mosteo, 2012/05/09