[Techtalk] real life kewl text-processing

Kathryn Hogg kjh at flyballdogs.com
Sat Jan 10 16:16:19 EST 2004


> #! /bin/sh
>
> # Translate filenames to lower case,
> # since Windows programs always seem to want to make them upper case.
>
> for fil in $* ; do
>   newfil=$(echo $fil | tr '[A-Z]' '[a-z]' )
>   if [ $newfil != $fil ]; then
>     mv $fil $newfil
>   fi

A simple enhancement which I use in a similar script is to allow the
filenames to have path components.  In this case, you want to leave the
patch components alone and only lowerize the filename component:

#!/bin/bash
for file in $*
do
  pathname=$(dirname $file)
  filename=$(basename $file)
  newfile=$(echo $file | tr '[:upper:]' '[:lower:]')
  if [ $filename != $newfile ]
  then
     mv $file $pathname/$newfile
  fi
done


-- 
Kathryn
http://womensfootyusa.com


More information about the Techtalk mailing list