#!/bin/bash if [ $# = 0 ]; then echo "Rename file(s) from one codepage to another" echo "Usage: mvconv [file{ file{ file{ ...}}}] [from codepage] [to codepage]" exit fi n=0 while [ "$1" != "" ]; do if [ -n "$var" ]; then eval "$var=$1" var= continue fi case $1 in [fF] | [fF][rR][oO][mM]) var=fromenc ;; [tT] | [tT][oO]) var=toenc ;; *) files[$n]="$1" ;; esac n=$(($n+1)) shift done iconv="iconv -c" [ -n "$fromenc" ] && iconv="$iconv -f $fromenc" [ -n "$toenc" ] && iconv="$iconv -t $toenc" while [ $n -gt 0 ]; do n=$(($n-1)) x=${files[$n]} y=`echo $x | $iconv 2>/dev/null` if [ "$x" != "$y" ]; then echo "Renaming $x to $y ..." mv "$x" "$y" fi done