Re: (somewhat OT:) lilypond calling bash script questions

2012-05-09 Thread Urs Liska

Thanks all for the generous feedback.

But the very simple solution that Jonas Olson posted quite early solved 
the issue.

"for dir in [0-9]*/;" was is exactly what I needed.

Best
Urs

Am 09.05.2012 16:31, schrieb Christopher Webster:


*From*: David Kastrup
*Subject*:  Re: (somewhat OT:) lilypond calling bash script questions
*Date*: Wed, 09 May 2012 16:01:54 +0200
*User-agent*:   Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux)


Christopher Webster  writes:

>/  A variant of Alex's suggestion (below):/
>
>/  find . -type d -name "[0-9]*" -print | while read dir/
>/  do/
>/   (/
>/   cd $dir;/
>/   for f in *.ly/
>/   do/
>/   lilypond $f/
>/   done/
>/   )/
>/  done/

find is looking _recursively_, arbitrarily deep.  It is the wrong tool
for the job.

--
David Kastrup

Apologies.  My misunderstanding.  I thought that recursion was the 
desired behaviour.  If not, then something more like this should do it:


for d in [0-9]*
do
if test -d $d
then
(
cd $d
for f in *.ly
do
lilypond $f
done
)
fi
done

Once again, I've typed this straight into the mail client without 
testing, so the obvious risks are present.


All the best

Christopher W.




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


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


Re: (somewhat OT:) lilypond calling bash script questions

2012-05-09 Thread Christopher Webster

-
*From*: David Kastrup
*Subject*: 	Re: (somewhat OT:) lilypond calling bash script 
questions

*Date*: Wed, 09 May 2012 16:01:54 +0200
*User-agent*:   Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux)

-
Christopher Webster  writes:

>/  A variant of Alex's suggestion (below):/
>
>/  find . -type d -name "[0-9]*" -print | while read dir/
>/  do/
>/   (/
>/   cd $dir;/
>/   for f in *.ly/
>/   do/
>/   lilypond $f/
>/   done/
>/   )/
>/  done/

find is looking _recursively_, arbitrarily deep.  It is the wrong tool
for the job.

--
David Kastrup

Apologies.  My misunderstanding.  I thought that recursion was 
the desired behaviour.  If not, then something more like this 
should do it:


for d in [0-9]*
do
if test -d $d
then
(
cd $d
for f in *.ly
do
lilypond $f
done
)
fi
done

Once again, I've typed this straight into the mail client without 
testing, so the obvious risks are present.


All the best

Christopher W.


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


Re: (somewhat OT:) lilypond calling bash script questions

2012-05-09 Thread Dossy Shiobara
This may or may not do exactly what you want:

find [0-9]* -name '*.ly' -print | while read f; do
cd `dirname $f`
lilypond `basename $f`
done

On 5/9/12 9:39 AM, Christopher Webster wrote:
> /How can I sequentially cd to all subdirectories that start with a number?/

-- 
Dossy Shiobara |  "He realized the fastest way to change
do...@panoptic.com |   is to laugh at your own folly -- then you
http://panoptic.com/   |   can let go and quickly move on." (p. 70) 
  * WordPress * jQuery * MySQL * Security * Business Continuity *

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


Re: (somewhat OT:) lilypond calling bash script questions

2012-05-09 Thread David Kastrup
Christopher Webster  writes:

> A variant of Alex's suggestion (below):
>
> find . -type d -name "[0-9]*" -print | while read dir
> do
>     (
>         cd $dir;
>         for f in *.ly
>         do
>             lilypond $f
>         done
>     )
> done

find is looking _recursively_, arbitrarily deep.  It is the wrong tool
for the job.

-- 
David Kastrup


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


Re: (somewhat OT:) lilypond calling bash script questions

2012-05-09 Thread Christopher Webster

A variant of Alex's suggestion (below):

find . -type d -name "[0-9]*" -print | while read dir
do
(
cd $dir;
for f in *.ly
do
lilypond $f
done
)
done

I've typed this directly in my mail client without testing it, so 
it's to be expected that some details will need correction.  
Sorry about that.



Christopher W.


*From*: Álex R . Mosteo
*Subject*: 	Re: (somewhat OT:) lilypond calling bash script 
questions

*Date*: Wed, 09 May 2012 11:37:47 +0200
*User-agent*:   KNode/4.8.3

-

Urs Liska wrote:


/  Please excuse if I post a linux question here, but I'd prefer not to/
/  have to find a dedicated forum and subscribe there first .../
/  /
/  I have a project with more than two dozens of lilypond scores. For/
/  several reasons I have them in individual files which I can't \include/
/  in a master file./
/  I would like to write a script that allows me to compile all .ly files/
/  in one run./


Another shot: if what you need is to compile all *.ly below a folder, this
might serve:

find . -name '*.ly' | while read i; do lilypond "$i"; done

Using read takes care of whitespace.

Or, more compact:

find . -name '*.ly' -exec lilypond '{}' \;

Although this won't work if the file must be inside a folder complying with
the number pattern.

Alex.


/  For this I need the following which I didn't find through Google:/
/  How can I sequentially cd to all subdirectories that start with a number?/
/  What I want is to do/
/  /
/  cd 01_01_.../
/  lilypond *.ly/
/  cd ../
/  cd 01_02_.../
/  ../
/  /
/  in a form like/
/  /
/  for dir in [get me all directories starting with a number]/
/  do/
/  cd $dir/
/  lilypond *.ly/
/  cd ../
/  done/
/  /
/  This _has_ to be absolutely simple, but I didn't manage do find out how/
/  so far./
/  /
/  Many thanks for any assistance./
/  Urs/




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


Re: (somewhat OT:) lilypond calling bash script questions

2012-05-09 Thread Álex R . Mosteo
Urs Liska wrote:

> Please excuse if I post a linux question here, but I'd prefer not to
> have to find a dedicated forum and subscribe there first ...
> 
> I have a project with more than two dozens of lilypond scores. For
> several reasons I have them in individual files which I can't \include
> in a master file.
> I would like to write a script that allows me to compile all .ly files
> in one run.

Another shot: if what you need is to compile all *.ly below a folder, this 
might serve:

find . -name '*.ly' | while read i; do lilypond "$i"; done

Using read takes care of whitespace.

Or, more compact:

find . -name '*.ly' -exec lilypond '{}' \;

Although this won't work if the file must be inside a folder complying with 
the number pattern.

Alex.

> For this I need the following which I didn't find through Google:
> How can I sequentially cd to all subdirectories that start with a number?
> What I want is to do
> 
> cd 01_01_...
> lilypond *.ly
> cd ..
> cd 01_02_...
> ..
> 
> in a form like
> 
> for dir in [get me all directories starting with a number]
> do
> cd $dir
> lilypond *.ly
> cd ..
> done
> 
> This _has_ to be absolutely simple, but I didn't manage do find out how
> so far.
> 
> Many thanks for any assistance.
> Urs



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


Re: (somewhat OT:) lilypond calling bash script questions

2012-05-08 Thread Reedmace Star
* 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:




R.S.

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


Re: (somewhat OT:) lilypond calling bash script questions

2012-05-08 Thread Urs Liska

Am 08.05.2012 11:46, schrieb Jan Kohnert:

Hi,

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.


[...]


in a form like

for dir in [get me all directories starting with a number]
do
cd $dir
lilypond *.ly
cd ..
done


This would be a bash solution:

for dir in $(find . -maxdepth 1 -type d -regex "^\.\/[0-9].*$"); do
   cd {dir}
   lilypond *.ly
   cd ..
done


Wow, that's where I had been looking around without success.
However, Jonas' and David's solution doesn't look as geeky but works 
perfectly.

Thanks
Urs

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


Re: (somewhat OT:) lilypond calling bash script questions

2012-05-08 Thread Jan Kohnert

Hi,

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.


[...]


in a form like

for dir in [get me all directories starting with a number]
do
cd $dir
lilypond *.ly
cd ..
done


This would be a bash solution:

for dir in $(find . -maxdepth 1 -type d -regex "^\.\/[0-9].*$"); do
   cd {dir}
   lilypond *.ly
   cd ..
done

--
Best regards Jan

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


Re: (somewhat OT:) lilypond calling bash script questions

2012-05-08 Thread David Kastrup
Urs Liska  writes:

> Please excuse if I post a linux question here, but I'd prefer not to
> have to find a dedicated forum and subscribe there first ...
>
> I have a project with more than two dozens of lilypond scores. For
> several reasons I have them in individual files which I can't \include
> in a master file.
> I would like to write a script that allows me to compile all .ly files
> in one run.
> For this I need the following which I didn't find through Google:
> How can I sequentially cd to all subdirectories that start with a number?
> What I want is to do
>
> cd 01_01_...
> lilypond *.ly
> cd ..
> cd 01_02_...
> ..
>
> in a form like
>
> for dir in [get me all directories starting with a number]
> do
> cd $dir
> lilypond *.ly
> cd ..
> done
>
> This _has_ to be absolutely simple, but I didn't manage do find out
> how so far.

for dir in [0-9]*/
do
  cd $dir
  lilypond *.ly
  cd ..
done

-- 
David Kastrup


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


Re: (somewhat OT:) lilypond calling bash script questions

2012-05-08 Thread Urs Liska

Am 08.05.2012 11:46, schrieb Jonas Olson:

On 2012-05-08 11:31, Urs Liska wrote:

cd 01_01_...
lilypond *.ly
cd ..
cd 01_02_...
..

in a form like

for dir in [get me all directories starting with a number]
do
cd $dir
lilypond *.ly
cd ..
done


Perhaps like so:
for dir in [0-9]*/;
do

cd $dir

lilypond *.ly

cd -

done

Jonas Olson

Thank you very much. That's it!
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: (somewhat OT:) lilypond calling bash script questions

2012-05-08 Thread Urs Liska

Am 08.05.2012 11:36, schrieb m...@apollinemike.com:

On 8 mai 2012, at 11:31, Urs Liska wrote:


Please excuse if I post a linux question here, but I'd prefer not to have to 
find a dedicated forum and subscribe there first ...

I have a project with more than two dozens of lilypond scores. For several 
reasons I have them in individual files which I can't \include in a master file.
I would like to write a script that allows me to compile all .ly files in one 
run.
For this I need the following which I didn't find through Google:
How can I sequentially cd to all subdirectories that start with a number?
What I want is to do

cd 01_01_...
lilypond *.ly
cd ..
cd 01_02_...
..

in a form like


I only speak Python, but I can help you there

import subprocess

NUMBER_OF_DIRS = 10

for x in range(NUMBER_OF_DIRS) :
   subprocess.call("lilypond *.ly", shell=True, cwd="01_"+("%.2d" % 
x)+"_foobar")

Note that I haven't tested the above, so I can't guarantee it works and you'd 
have to adapt it to your individual case.

Cheers,
MS


Well, I don't speak Python, so I'll hope to get another response.

But from what I can decipher from your script I might have to express 
myself clearer:
The condition for the inclusion of a directory is _only_ that it starts 
with a number.
The dirs with scores in it are named according to opus number, thus 
starting with a two digit number, followed by an underscore and another 
two digit number.
But the unique characteristic is that it begins with a number, as all 
other directories below the project root start with characters.


Thanks anyway
Urs

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



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


Re: (somewhat OT:) lilypond calling bash script questions

2012-05-08 Thread Jonas Olson

On 2012-05-08 11:31, Urs Liska wrote:

cd 01_01_...
lilypond *.ly
cd ..
cd 01_02_...
..

in a form like

for dir in [get me all directories starting with a number]
do
cd $dir
lilypond *.ly
cd ..
done


Perhaps like so:

for dir in [0-9]*/;

do

   cd $dir

   lilypond *.ly

   cd -

done


Jonas Olson
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: (somewhat OT:) lilypond calling bash script questions

2012-05-08 Thread m...@apollinemike.com
On 8 mai 2012, at 11:31, Urs Liska wrote:

> Please excuse if I post a linux question here, but I'd prefer not to have to 
> find a dedicated forum and subscribe there first ...
> 
> I have a project with more than two dozens of lilypond scores. For several 
> reasons I have them in individual files which I can't \include in a master 
> file.
> I would like to write a script that allows me to compile all .ly files in one 
> run.
> For this I need the following which I didn't find through Google:
> How can I sequentially cd to all subdirectories that start with a number?
> What I want is to do
> 
> cd 01_01_...
> lilypond *.ly
> cd ..
> cd 01_02_...
> ..
> 
> in a form like
> 

I only speak Python, but I can help you there

import subprocess

NUMBER_OF_DIRS = 10

for x in range(NUMBER_OF_DIRS) :
  subprocess.call("lilypond *.ly", shell=True, cwd="01_"+("%.2d" % x)+"_foobar")

Note that I haven't tested the above, so I can't guarantee it works and you'd 
have to adapt it to your individual case.

Cheers,
MS
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


(somewhat OT:) lilypond calling bash script questions

2012-05-08 Thread Urs Liska
Please excuse if I post a linux question here, but I'd prefer not to 
have to find a dedicated forum and subscribe there first ...


I have a project with more than two dozens of lilypond scores. For 
several reasons I have them in individual files which I can't \include 
in a master file.
I would like to write a script that allows me to compile all .ly files 
in one run.

For this I need the following which I didn't find through Google:
How can I sequentially cd to all subdirectories that start with a number?
What I want is to do

cd 01_01_...
lilypond *.ly
cd ..
cd 01_02_...
..

in a form like

for dir in [get me all directories starting with a number]
do
cd $dir
lilypond *.ly
cd ..
done

This _has_ to be absolutely simple, but I didn't manage do find out how 
so far.


Many thanks for any assistance.
Urs


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