-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchext.sh
More file actions
executable file
·27 lines (21 loc) · 781 Bytes
/
chext.sh
File metadata and controls
executable file
·27 lines (21 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/bash
# By Julien MOREAU aka PixEye
nbwp=2 # Number of wanted parameters
cmd=${0##*/} # Command name
usage="Usage: $cmd <ext1> <ext2>" # Help message
usage=$usage"\n\tChange the extension of all files from the current directory"
usage=$usage"\n\t ending with \".<ext1>\" with new extension <ext2>."
usage=$usage"\n\tReturn the number of renamed files."
if test `uname` != "HP-UX" ; then e="-e" ; fi # shall we use the -e option for echo?
if [ $# -ne $nbwp ] # If there is NOT the right number of parameters,
then echo $e $usage 1>&2 ; exit 2 # Display the help message & stop.
fi
n=0
for fic in *.$1
do
new="`echo $fic|sed -e 's/^\(.*\)\.[^\.]*$/\1/'`.$2"
echo $e "$fic -> $new"
mv -i -- "$fic" "$new"
n=`expr $n + 1`
done
exit $n # Number of changed filenames