Patch-ID: bash32-044
[bash.git] / examples / scripts.v2 / lowercase
blobfd2ec5d65ee3e1c7ae99cdc3b64f7f000b0481c4
1 #! /bin/bash
3 # original from
4 # @(#) lowercase.ksh 1.0 92/10/08
5 # 92/10/08 john h. dubois iii (john@armory.com)
7 # conversion to bash v2 syntax done by Chet Ramey
9 Usage="Usage: $name file ..."
10 phelp()
12 echo "$name: change filenames to lower case.
13 $Usage
14 Each file is moved to a name with the same directory component, if any,
15 and with a filename component that is the same as the original but with
16 any upper case letters changed to lower case."
19 name=${0##*/}
21 while getopts "h" opt; do
22 case "$opt" in
23 h) phelp; exit 0;;
24 *) echo "$Usage" 1>&2; exit 2;;
25 esac
26 done
28 shift $((OPTIND - 1))
30 for file; do
31 filename=${file##*/}
32 case "$file" in
33 */*) dirname=${file%/*} ;;
34 *) dirname=. ;;
35 esac
36 nf=$(echo $filename | tr A-Z a-z)
37 newname="${dirname}/${nf}"
38 if [ "$nf" != "$filename" ]; then
39 mv "$file" "$newname"
40 echo "$0: $file -> $newname"
41 else
42 echo "$0: $file not changed."
44 done