lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Lilypond & Ubuntu Help


From: Patrick Horgan
Subject: Re: Lilypond & Ubuntu Help
Date: Mon, 18 Aug 2008 11:42:20 -0700
User-agent: Thunderbird 2.0.0.16 (X11/20080724)

Jonathan Kulp wrote:
Nice!  Thanks for this, Patrick!  It works just right.  Now I have to look at it to figure out *why* it works the way it does ;-)  I haven't used that sort of construct before...

Jonathan

Patrick Horgan wrote:

Instead of basename you could use the built in string manipulation stuff this:

# determines the source filename
srcfile=`basename $1`

# removes the extension from source filename
FILENOEXTENSION=${srcfile%.*}
See the info manual for bash under 3.5.3 Shell Parameter Expansion.

You could also do:

srcfile=${1##*/}                # subtract the longest prefix of $1 ending with /       
FILENOEXTENSION=${srcfile%.*}   # subtract shortest suffix starting with .
OUTDIR=${1%/*}                  # subtract shortest suffix starting with /                

## means match the longest possible pattern on the end, and delete it from the beginning of the variable ($1 in this case).  The pattern is */ and means delete anything ending with a /.
If I'd used one # it would delete the shortest match to the pattern.
so if the $1 held /usr/local/lilypond/file.ly
srcfile=${1#*/}
would yield local/lilypond/file.ly, not very good, but with ## we get the whole path off.
% means the same thing, only delete the matched part off of the end.  There's also a %% that means delete the longest match off the end.
There's also stuff for substring matches and string lengths, and offset to a found match and more!  Should work with bash, sh, and any shell compatible.  Probably not zsh, they're in a different universe.


Patrick

reply via email to

[Prev in Thread] Current Thread [Next in Thread]