Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

zsh changing cp1250 letters beyond recognition



Hi.

I have written simple script (attached) that gets filenames (in $*).
The filenames possibly contain letters in cp1250 (windows encoding for
middle and eastern Europe) or iso-8859-2.

It should change the letters with accents to plain ascii and if
there's a difference between the original and new name, it renames the
file.

Now, if I use bash to run the script, everything works just fine. But
when I replace #!/bin/bash with #!/bin/zsh, all those strange cp1250
characters (\232\235\236\212\215\216) get replaced with other (and
equally strange) ones. Renaming and tr don't work correctly then.

As an example, I attach a small file you can try to run (to see the
behavior) -- runme.sh and outputs:

with bash:

mv 03 - Tři sudičky.mp3 03 - Tri sudicky.mp3
mv 04 - Ma?karní plesy.mp3 04 - Maskarni plesy.mp3
mv 05 - Setkání s Pu?kinem.mp3 05 - Setkani s Puskinem.mp3
mv 06 - Svlíkni si ko?ilku.mp3 06 - Svlikni si kosilku.mp3
mv 07 - Píseň psaná na vodu.mp3 07 - Pisen psana na vodu.mp3
mv 08 - Kdy? mě brali za vojáka.mp3 08 - Kdyz me brali za vojaka.mp3
mv 10 - Děvenka ?těstí a mládenec ?al.mp3 10 - Devenka Stesti a mladenec Zal.mp3
mv 11 - Básníci chlípníci.mp3 11 - Basnici chlipnici.mp3
mv 12 - Zestárli jsme lásko.mp3 12 - Zestarli jsme lasko.mp3
mv 13 - Třiatřicet.mp3 13 - Triatricet.mp3
mv 14 - Vla?tovky.mp3 14 - Vlastovky.mp3
mv 15 - Píseň pro Lenku.mp3 15 - Pisen pro Lenku.mp3
mv 19 - Přelezl jsem plot.mp3 19 - Prelezl jsem plot.mp3

and with zsh (differences in 04, 05, 06, 10...):

mv 03 - Tři sudičky.mp3 03 - Tri sudicky.mp3
mv 04 - Makarní plesy.mp3 04 - Makarni plesy.mp3
mv 05 - Setkání s Pukinem.mp3 05 - Setkani s Pukinem.mp3
mv 06 - Svlíkni si koilku.mp3 06 - Svlikni si koilku.mp3
mv 07 - Píseň psaná na vodu.mp3 07 - Pisen psana na vodu.mp3
mv 08 - Kdy? mě brali za vojáka.mp3 08 - Kdyz me brali za vojaka.mp3
mv 10 - Děvenka $těstí a mládenec }al.mp3 10 - Devenka $testi a mladenec }al.mp3
mv 11 - Básníci chlípníci.mp3 11 - Basnici chlipnici.mp3
mv 12 - Zestárli jsme lásko.mp3 12 - Zestarli jsme lasko.mp3
mv 13 - Třiatřicet.mp3 13 - Triatricet.mp3
mv 15 - Píseň pro Lenku.mp3 15 - Pisen pro Lenku.mp3
mv 19 - Přelezl jsem plot.mp3 19 - Prelezl jsem plot.mp3


Jan

-- 
  Jan Fedak                            talk:jack@xxxxxxxxxxxxxxxxxx
  mailto:J.Fedak@xxxxxxxxxx                    mailto:jack@xxxxxxxx
                Linux - the ultimate NT Service Pack.  
#!/bin/bash
# ^ must have bash here. possibly a bug in zsh renders this script useless

trfrom='áčďěéíňóř\232\235ůúý\236ÁČĎÉĚÍŇÓŘ\212\215ŮÚÝ\216'
trto='acdeeinorstuuyzACDEEINORSTUUYZ'
if [ "x$1" = x-iso ]; then
    trfrom='áčďěéíňóřšťůúýžÁČĎÉĚÍŇÓŘŠŤŮÚÝŽ'
    shift
fi

while [ $# -gt 0 ]; do
    name="$1"
    shift
    nonczname=`echo "$name" | tr $trfrom $trto`
    if [ "$name" != "$nonczname" ]; then
	echo mv "$name" "$nonczname"
	mv "$name" "$nonczname"
    fi
done

Attachment: runme.sh
Description: Bourne shell script



Messages sorted by: Reverse Date, Date, Thread, Author