4 # newext: change filename extension
5 # @(#) newext.sh 1.1 93/04/13
6 # 90/06/06 john h. dubois iii (john@armory.com)
7 # 90/11/14 changed ksh-specific code to hybrid: if running under Bourne,
8 # uses expr instead of ksh builtin ops. Removed SYSV specific code.
9 # 91/08/06 added -t option
10 # 92/11/06 made earlier code actually work!
11 # 93/04/13 If no filenames given, act on files in current dir
13 # conversion to bash v2 syntax by Chet Ramey
15 usage
="Usage: newext [-th] <oldext> <newext> [filename ...]"
20 Rename all given files that end in oldext with newext replacing oldext.
21 If no filenames are given, all files in the current directory that end
22 in oldext are acted on (no filename is equivalent to '*').
25 -t: Test: No action is taken except to print the mv commands that would
26 be executed if -t was not given."
29 while getopts "th" opt
; do
33 *) echo "$usage" 1>&2; exit 2;;
43 [01]) echo -e "$usage\nUse -h for help." 1>&2; exit 2;;
44 2) shift ; shift; set -- *;;
54 newname
="${file%$oldext}$newext"
55 $echo mv "$file" "$newname"
60 if [ -z "$found" ]; then
61 echo "No files ending in \"$oldext\"."