[Leaplist] teach me please about this code
John Simpson
jms1 at jms1.net
Sat Jan 5 03:30:08 GMT 2008
On 2008-01-03, at 1951, tonyb wrote:
>
> The easy way to understand it is by using echo to display the
> interesting pieces:
> ...
>
> for i in *.m4a
> do
> echo "$i"
> echo "${i%m4a}mp3"
> done
>
> aa.m4a
> aa.mp3
> bb.m4a
> bb.mp3
> cc.m4a
> cc.mp3
is the ${...%pattern} operator specific to bash, or does it work with
any /bin/sh variant?
reading the man page about it, i also find a ${.../pattern/string}
operator. i remember reading about these before, but i couldn't get my
head wrapped around what they were doing, and it wasn't relevant to
what i was working on at the time, so i ignored it but always meant to
get back to it... and of course, never did.
i just wrote a test script to show me what these operators actually
do. i find it easier to understand if i can see a list of "before and
after" cases...
$x abc_123_abc_789_abc
${x%abc}XYZ abc_123_abc_789_XYZ
${x#abc}XYZ _123_abc_789_abcXYZ
${x/abc/XYZ} XYZ_123_abc_789_abc
${x//abc/XYZ} XYZ_123_XYZ_789_XYZ
${x/#abc/XYZ} XYZ_123_abc_789_abc
----------------------------------------------------------------
| John M. Simpson --- KG4ZOW --- Programmer At Large |
| http://www.jms1.net/ <jms1 at jms1.net> |
----------------------------------------------------------------
| http://video.google.com/videoplay?docid=-1656880303867390173 |
----------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
Url : http://lists.leap-cf.org/pipermail/leaplist/attachments/20080104/770b16d6/PGP.bin
More information about the Leaplist
mailing list