source: vendor/bash/3.1-p17/examples/scripts.v2/lowercase

Last change on this file was 3228, checked in by bird, 18 years ago

bash 3.1

File size: 933 bytes
Line 
1#! /bin/bash
2#
3# original from
4# @(#) lowercase.ksh 1.0 92/10/08
5# 92/10/08 john h. dubois iii (john@armory.com)
6#
7# conversion to bash v2 syntax done by Chet Ramey
8
9Usage="Usage: $name file ..."
10phelp()
11{
12echo "$name: change filenames to lower case.
13$Usage
14Each file is moved to a name with the same directory component, if any,
15and with a filename component that is the same as the original but with
16any upper case letters changed to lower case."
17}
18
19name=${0##*/}
20
21while getopts "h" opt; do
22 case "$opt" in
23 h) phelp; exit 0;;
24 *) echo "$Usage" 1>&2; exit 2;;
25 esac
26done
27
28shift $((OPTIND - 1))
29
30for 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."
43 fi
44done
Note: See TracBrowser for help on using the repository browser.