On Sunday 8 July 2007 23:18, Mick wrote:

> Thanks Alex, I was trying your script, but just like Etaoin's script
> it does not go beyond level 1 in the directory.  All the
> subdirectories and files within them stay in Capital Case.
>
> How can I change it to recursively look into the directory?

One way is to use recursion (btw, my previous script had an error: tr 
must be invoked without the -s option):

#!/bin/bash

# $1 is the file/dir name
function change_case() {
  newname=`echo $1 | tr 'A-Z' 'a-z'`
  echo "$1 -> $newname"  # for debug
  mv $1 $newname
}

function scan() {
  local i
  for i in $*; do
    if [ -d $i ]; then
      # $i is a directory, recurse and change case
      cd $i
      scan *
      cd ..
      change_case $i
    else
      # regular file
      change_case $i
    fi
  done
}

# start
if [ $# -eq 0 ]; then
  echo "Must specify root directory"
  exit 1
fi

shopt -s nullglob    # to account for empty dirs
cd $1
scan *
exit 0
-- 
[EMAIL PROTECTED] mailing list

Reply via email to